# run this chnck of code to get the vector `x`
x <- c(8:12, 5, 18:10)
x
##  [1]  8  9 10 11 12  5 18 17 16 15 14 13 12 11 10

Q1 Write R code to create the matrix A using vector x

\[ A = \begin{pmatrix} 8 & 9 & 10\\ 11 & 12 & 5 \\ 18 & 17 & 16 \\ 15 & 14 & 13 \\ 12 & 11 & 10 \end{pmatrix} \]

A <- matrix(x, nrow = 5, ncol = 3, byrow = TRUE)
A
##      [,1] [,2] [,3]
## [1,]    8    9   10
## [2,]   11   12    5
## [3,]   18   17   16
## [4,]   15   14   13
## [5,]   12   11   10

Q2 Write a R code to access the element at 2nd row and 3rd column of

A[2, 3]
## [1] 5

Q3 Write a R code to access only the 2th column of the matrix

A[, 2]
## [1]  9 12 17 14 11

Q4 Write a R code to access columns 1 & 3 of the matrix

A[, c(1,3)]
##      [,1] [,2]
## [1,]    8   10
## [2,]   11    5
## [3,]   18   16
## [4,]   15   13
## [5,]   12   10

Q5 Write a R code to access rows 1 through 3 of the matrix

A[1:3, ]
##      [,1] [,2] [,3]
## [1,]    8    9   10
## [2,]   11   12    5
## [3,]   18   17   16

Q6 Write R code to convert matrix A to a list of column-vectors, save it as L

L <- split(A, col(A))
L
## $`1`
## [1]  8 11 18 15 12
## 
## $`2`
## [1]  9 12 17 14 11
## 
## $`3`
## [1] 10  5 16 13 10

Q7 Write a code to access the 3rd element of L

L[[3]]
## [1] 10  5 16 13 10

Q8 write a R code to extract the submatrix of A whose 2nd column values are all grater than 12.

A[A[, 2] > 12, ]
##      [,1] [,2] [,3]
## [1,]   18   17   16
## [2,]   15   14   13

Q9 Write R code to determine the location (index) of the minimum of vector x

which.min(x)
## [1] 6

Q10 Write R code to determine the location (index) of the minimum of matrix A

which.min(A)
## [1] 12
which(A == min(A), arr.ind = TRUE)
##      row col
## [1,]   2   3

Q11 write R code to determine the indices all the elemnts of x divisible by 5

which(x %% 5 == 0)
## [1]  3  6 10 15

Q12 write R code to extract all the elements of x not divisible by 5

x[x %% 5 != 0]
##  [1]  8  9 11 12 18 17 16 14 13 12 11

Q13 Write R code to find the transpose of the matrix A

t(A)
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    8   11   18   15   12
## [2,]    9   12   17   14   11
## [3,]   10    5   16   13   10