To select the rows of a matrix that meet a condition, you can do the following:
To create the matrix:
M <- matrix(c(1:20), nrow = 5, ncol =4)
colnames(M) <- c("one", "two", "three","four")
M
one two three four
[1,] 1 6 11 16
[2,] 2 7 12 17
[3,] 3 8 13 18
[4,] 4 9 14 19
[5,] 5 10 15 20
To select a column by name:
M[M[, "three"] == 11,]
one two three four
1 6 11 16
To select a column by number:
M[M[, 3] == 11,]
one two three four
1 6 11 16
To keep the selected column(s) as matrices:
M[M[,3] == 11,,drop = FALSE]
one two three four
[1,] 1 6 11 16
class(M[M[,3] == 11,,drop = FALSE])
[1] "matrix"