@nirgrahamuk & @fcas80 have to say about SD
. To subset within 2:9
m <- matrix(sample(1:20,15),sample(1:20,15), nrow = 15,ncol = 15)
m
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [2,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [3,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [4,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [5,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [6,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [7,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [8,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [9,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [10,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [11,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [12,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [13,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [14,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [15,] 16 12 9 20 11 1 10 13 18 2 5 19 14
#> [,14] [,15]
#> [1,] 17 7
#> [2,] 17 7
#> [3,] 17 7
#> [4,] 17 7
#> [5,] 17 7
#> [6,] 17 7
#> [7,] 17 7
#> [8,] 17 7
#> [9,] 17 7
#> [10,] 17 7
#> [11,] 17 7
#> [12,] 17 7
#> [13,] 17 7
#> [14,] 17 7
#> [15,] 17 7
# elements will be coming out, zapping the matrix structure, so
# use a vector
v <- c(m)
v
#> [1] 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 12 12 12 12 12 12 12 12 12 12
#> [26] 12 12 12 12 12 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 20 20 20 20 20
#> [51] 20 20 20 20 20 20 20 20 20 20 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
#> [76] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 10 10 10 10 10 10 10 10 10
#> [101] 10 10 10 10 10 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 18 18 18 18 18
#> [126] 18 18 18 18 18 18 18 18 18 18 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
#> [151] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 19 19 19 19 19 19 19 19 19 19
#> [176] 19 19 19 19 19 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 17 17 17 17 17
#> [201] 17 17 17 17 17 17 17 17 17 17 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
v[v > 1 & v < 10]
#> [1] 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 5 5
#> [39] 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
Created on 2022-11-24 by the reprex package (v2.0.1)