Skip to content
Prev 165710 / 398502 Next

Randomly remove condition-selected rows from a matrix

I believe this does what you want:

m[-sample(which(m[,1]<8 & m[,2]>12),2),]

Analysis:

Get a boolean vector of rows fitting criteria:
    m[,1]<8 & m[,2]>12

What are their indexes?
    which(...)

Choose two among those indexes:
     sample(...,2)

Choose all except the selected rows from the original:
     m[- ... , ]

          -s

On Tue, Dec 30, 2008 at 9:59 AM, Guillaume Chapron
<carnivorescience at gmail.com> wrote: