a. Arithmetic Operations
2 + 3 + 5
## [1] 10
12-4
## [1] 8
3*3
## [1] 9
20/5
## [1] 4
4^4
## [1] 256
8^(1/3)
## [1] 2
log10(100)
## [1] 2
b. to d. Vector
c <- c(2,3,4,5,6,7)
list(c[3])
## [[1]]
## [1] 4
length(c)
## [1] 6
e. to g. Matrix
#Matrix with 2 rows and 4 columns
d <- matrix(c(1,3,5,7,2,4,6,8), nrow = 2, byrow = TRUE)
d
##      [,1] [,2] [,3] [,4]
## [1,]    1    3    5    7
## [2,]    2    4    6    8
#Add 5 to each element in the matrix
F <- d + 5
F
##      [,1] [,2] [,3] [,4]
## [1,]    6    8   10   12
## [2,]    7    9   11   13
#dimension of "F"
dim(F)
## [1] 2 4
h. to l. Data Type and Coersion
k <- 5.25
m <- "frank"
class(k)
## [1] "numeric"
class(m)
## [1] "character"
#Convert to an integer
p <- as.integer(k)
p
## [1] 5
#Convert to character
G <- as.character(k)

The numeric variable “k”" was coerced into a character variable “G”. Adding 5.1 to G produces an error because arithmetic operations require numeric variables.