$ R
a <- matrix(1:6, nrow=2, ncol=3)
a
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
b <- matrix(1:6, nrow=2, ncol=3, byrow=T)
b
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
x <- matrix(1:30, nrow=6, ncol=5)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 7 13 19 25
[2,] 2 8 14 20 26
[3,] 3 9 15 21 27
[4,] 4 10 16 22 28
[5,] 5 11 17 23 29
[6,] 6 12 18 24 30
x[1,4]
[1] 19
x[c(1,2), 2]
[1] 7 8
x[2:4, 2]
[1] 8 9 10
x[c(2,4), 2]
[1] 8 9 10
x[c(2,2), c(5,3)]
[,1] [,2]
[1,] 26 14
[2,] 26 14
x[ ,-c(1, 3)]
[,1] [,2] [,3]
[1,] 7 19 25
[2,] 8 20 26
[3,] 9 21 27
[4,] 10 22 28
[5,] 11 23 29
[6,] 12 24 30
x[ ,c(1:3)]
[,1] [,2] [,3]
[1,] 1 7 13
[2,] 2 8 14
[3,] 3 9 15
[4,] 4 10 16
[5,] 5 11 17
[6,] 6 12 18
x[ , c(T,T,T,F,F)]
[,1] [,2] [,3]
[1,] 1 7 13
[2,] 2 8 14
[3,] 3 9 15
[4,] 4 10 16
[5,] 5 11 17
[6,] 6 12 18
rowSums(x)
[1] 65 70 75 80 85 90
colSums(x)
[1] 21 57 93 129 165
rowMeans(x)
[1] 13 14 15 16 17 18
colMeans(x)
[1] 3.5 9.5 15.5 21.5 27.5
x <- rbind(c(1:6), c(2:7), c(3:8))
x
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 2 3 4 5 6
[2,] 2 3 4 5 6 7
[3,] 3 4 5 6 7 8
y <- cbind(c(1:6), c(2:7), c(3:8))
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 2 3 4
[3,] 3 4 5
[4,] 4 5 6
[5,] 5 6 7
[6,] 6 7 8