matrix() to create a matrixt() : matrix transposeas.vector() : convert a matrix to a vectorsplit(M, col(M)) : Split a matrix into a list by
columnswhich.min(), which.max()which()# 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
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
A[2, 3]
## [1] 5
A[, 2]
## [1] 9 12 17 14 11
A[, c(1,3)]
## [,1] [,2]
## [1,] 8 10
## [2,] 11 5
## [3,] 18 16
## [4,] 15 13
## [5,] 12 10
A[1:3, ]
## [,1] [,2] [,3]
## [1,] 8 9 10
## [2,] 11 12 5
## [3,] 18 17 16
A to a list of
column-vectors, save it as LL <- 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
LL[[3]]
## [1] 10 5 16 13 10
A[A[, 2] > 12, ]
## [,1] [,2] [,3]
## [1,] 18 17 16
## [2,] 15 14 13
xwhich.min(x)
## [1] 6
Awhich.min(A)
## [1] 12
which(A == min(A), arr.ind = TRUE)
## row col
## [1,] 2 3
x divisible by 5which(x %% 5 == 0)
## [1] 3 6 10 15
x not
divisible by 5x[x %% 5 != 0]
## [1] 8 9 11 12 18 17 16 14 13 12 11
At(A)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 8 11 18 15 12
## [2,] 9 12 17 14 11
## [3,] 10 5 16 13 10