Try this:

 which(colSums(t(combs) == x) == ncol(combs))

On Wed, Jan 5, 2011 at 5:16 PM, Kevin Ummel <kevinum...@gmail.com> wrote:

> Two posts in one day is not a good day...and this question seems like it
> should have an obvious answer:
>
> I have a matrix where rows are unique combinations of 1's and 0's:
>
> > combs=as.matrix(expand.grid(c(0,1),c(0,1)))
> > combs
>     Var1 Var2
> [1,]    0    0
> [2,]    1    0
> [3,]    0    1
> [4,]    1    1
>
> I want a single function that will give the row index containing an exact
> match with vector x:
>
> > x=c(0,1)
>
> The solution needs to be applied many times, so I need something quick -- I
> was hoping a base function would do it, but I'm drawing a blank.
>
> Thanks!
> Kevin
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[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.

Reply via email to