[R] Filter a Matrix

Ben Bolker bbolker at gmail.com
Wed Dec 1 01:37:50 CET 2010


Jorge Ivan Velez <jorgeivanvelez <at> gmail.com> writes:

> 
> Hi Romildo,
> 
> One possible way would be the following:
> 
> index <- apply(m, 1, function(row) any(a %in% row))
> m[index, ]
> 
> HTH,
> Jorge
> 

  Does the original poster mean 

 index <- apply(m, 1, function(row) all(a %in% row))
 m[index, ]

?

A little hard to tell because in the original example 'all'
and 'any' would give the same answers -- 2 and 6 always occur
together.



More information about the R-help mailing list