Name and ID: Vanessa Situ 702746674
# Your code goes here
7+4
## [1] 11
(3*8)/(2*3)
## [1] 4
# Your code goes here
print(7+4)
## [1] 11
print((3*8)/(2*3))
## [1] 4
# Your code goes here
log(12)
## [1] 2.484907
log(12, base=10)
## [1] 1.079181
sqrt(121)
## [1] 11
pi
## [1] 3.141593
# Your code goes here
x = 7
y = 4
x+y
## [1] 11
z<- 3
k<-4
print (z+k)
## [1] 7
# Your code goes here
a <- c(1, 2, 5, -4, -6,-7)
b <- c(TRUE,FALSE)
c <- c("one", "two", "three")
d <- c(1 + 2*4, 3-6*7)
a
## [1] 1 2 5 -4 -6 -7
b
## [1] TRUE FALSE
c
## [1] "one" "two" "three"
d
## [1] 9 -39
# Your code goes here
a <- c(1, 2, 5, -4, -6,-7)
b <- c(TRUE,FALSE)
c <- c("one","two","three")
a
## [1] 1 2 5 -4 -6 -7
b
## [1] TRUE FALSE
c
## [1] "one" "two" "three"
class(a)
## [1] "numeric"
class(b)
## [1] "logical"
class(c)
## [1] "character"
# Your code goes here
Y<-vector("numeric",length = 1)
Y
## [1] 0
class(Y)
## [1] "numeric"
# Your code goes here
d<-as.integer(3)
d
## [1] 3
class(d)
## [1] "integer"
# Your code goes here
a<-0:5
a
## [1] 0 1 2 3 4 5
class(a)
## [1] "integer"
# Your code goes here
a <- c(2/5)
class(a)
## [1] "numeric"
a
## [1] 0.4
b = as.character(a)
class(b)
## [1] "character"
b
## [1] "0.4"
# Your code goes here
df <- data.frame(name =c("ash","paul","jane","mark"),grade=c(88,93,78,65))
df
## name grade
## 1 ash 88
## 2 paul 93
## 3 jane 78
## 4 mark 65
# Your code goes here
df <- data.frame(name =c("ash","paul","jane","mark"),grade=c(88,93,78,65))
str(df)
## 'data.frame': 4 obs. of 2 variables:
## $ name : chr "ash" "paul" "jane" "mark"
## $ grade: num 88 93 78 65
ncol(df)
## [1] 2
nrow(df)
## [1] 4
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data
## ID month sales region
## 1 1 Jan 15000 east
## 2 2 Feb 20000 west
## 3 3 March 125000 south
## 4 4 Apr 40000 north
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<c(1500,20000,125000,40000)
## [1] FALSE FALSE FALSE FALSE
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data[2]
## month
## 1 Jan
## 2 Feb
## 3 March
## 4 Apr
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(1500,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data[,2]
## [1] "Jan" "Feb" "March" "Apr"
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data[2,]
## ID month sales region
## 2 2 Feb 20000 west
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data[c("month","region")]
## month region
## 1 Jan east
## 2 Feb west
## 3 March south
## 4 Apr north
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data$sales
## [1] 15000 20000 125000 40000
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data[1:2]
## ID month
## 1 1 Jan
## 2 2 Feb
## 3 3 March
## 4 4 Apr
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
Sales_Data<-data.frame(ID,month,sales,region)
Sales_Data[1,2]
## [1] "Jan"
Sales_Data[2,3]
## [1] 20000
Sales_Data[3,4]
## [1] "south"
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
performance<-c("Poor","Poor","Excellent","Average")
performance<-factor(performance,order=TRUE)
Sales_Data<-data.frame(ID,month,sales,region,performance)
Sales_Data
## ID month sales region performance
## 1 1 Jan 15000 east Poor
## 2 2 Feb 20000 west Poor
## 3 3 March 125000 south Excellent
## 4 4 Apr 40000 north Average
# Your code goes here
ID<-c(1,2,3,4)
month<-c("Jan","Feb","March","Apr")
sales<-c(15000,20000,125000,40000)
region<-c("east","west","south","north")
performance<-c("Poor","Poor","Excellent","Average")
performance<-factor(performance,order=TRUE)
Sales_Data<-data.frame(ID,month,sales,region,performance)
str(Sales_Data)
## 'data.frame': 4 obs. of 5 variables:
## $ ID : num 1 2 3 4
## $ month : chr "Jan" "Feb" "March" "Apr"
## $ sales : num 15000 20000 125000 40000
## $ region : chr "east" "west" "south" "north"
## $ performance: Ord.factor w/ 3 levels "Average"<"Excellent"<..: 3 3 2 1
x=as.integer(performance)
x
## [1] 3 3 2 1