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
<carnivorescie...@gmail.com> wrote:

> m <- matrix(1:20, nrow = 10, ncol = 2)
>         [,1] [,2]
>  [1,]    1   11
>  [2,]    2   12
>  [3,]    3   13
>  [4,]    4   14
>  [5,]    5   15
>  [6,]    6   16
>  [7,]    7   17
>  [8,]    8   18
>  [9,]    9   19
> [10,]   10   20
>
> Then, I want to remove randomly 2 rows among the ones where m[,1]<8 and
> m[,2]>12

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to