Hi Romildo,

One possible way would be the following:

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

HTH,
Jorge


On Tue, Nov 30, 2010 at 7:18 PM, Romildo Martins <> wrote:

> Hello,
>
> How to filter the matrix (m) based on the array (a)?
>
> > m
>     [,1] [,2] [,3]
> [1,]    5    1    4
> [2,]    2    6    2
> [3,]    3    4    7
> [4,]    1    2    6
> [5,]    1    5    3
> [6,]    7    6    2
>
> > a
> [1] 2 6
>
> > output
>     [,1] [,2] [,3]
> [1,]    2    6    2
> [2,]    1    2    6
> [3,]    7    6    2
>
>
> Thanks a lot!
>
> RMB
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

