Skip to content

subsetting a matrix based on condition

2 messages · A Ezhil, Dimitris Rizopoulos

#
Dear All,

I have matrix of size 2500 x 12. I would like to select all the rows if 6 out 12 values are > 0. How can I do that in R? 

Thanks in advance.

Kind regards,
Ezhil
#
one way is:

mat <- matrix(rnorm(2500*12), 2500, 12)

ind <- rowSums(mat > 0) > 6
mat[ind, ]


I hope it helps.

Best,
Dimitris
A Ezhil wrote: