I am trying to figure out a way to delete matrix rows if a cell in that row satisfies a certain characteristic. For instance:
> mm <- matrix(c(1,2,3,2,3,4,1,2,3,4),5,2) > mm [,1] [,2] [1,] 1 4 [2,] 2 1 [3,] 3 2 [4,] 2 3 [5,] 3 4
I want to delete rows if the 1st column element in this row is 2. At the end I want:
[,1] [,2] [1,] 1 4 [2,] 3 2 [3,] 3 4
How can i do this?
What about a more general method, if instead of deleting all rows for which the first column element is 2, I had to delete rows for which the first column element corresponds to the set of numbers contained in the list? for instance
delete_list <- c(2,3)
What is the best way to do this?
Thanks in advance.
source share