Re: [R] Matching a vector with a matrix row

2011-04-24 Thread Ravi Varadhan
n Behalf Of Petr Savicky [savi...@praha1.ff.cuni.cz] Sent: Sunday, April 24, 2011 5:13 AM To: r-help@r-project.org Subject: Re: [R] Matching a vector with a matrix row On Sat, Apr 23, 2011 at 08:56:33AM +0800, Luis Felipe Parra wrote: > Hello Niels, I am trying to find the rows in Matrix whic

Re: [R] Matching a vector with a matrix row

2011-04-24 Thread Petr Savicky
On Sat, Apr 23, 2011 at 08:56:33AM +0800, Luis Felipe Parra wrote: > Hello Niels, I am trying to find the rows in Matrix which contain all of the > elements in LHS. This sounds like you want an equivalent of all(LHS %in% x) However, in your original post, you used all(x %in% LHS) What is c

Re: [R] Matching a vector with a matrix row

2011-04-22 Thread Ravi Varadhan
arra [felipe.pa...@quantil.com.co] Sent: Friday, April 22, 2011 8:56 PM To: Niels Richard Hansen Cc: r-help Subject: Re: [R] Matching a vector with a matrix row Hello Niels, I am trying to find the rows in Matrix which contain all of the elements in LHS. Thank you Felipe Parra On Fri, Apr 22, 2

Re: [R] Matching a vector with a matrix row

2011-04-22 Thread Luis Felipe Parra
Hello Niels, I am trying to find the rows in Matrix which contain all of the elements in LHS. Thank you Felipe Parra On Fri, Apr 22, 2011 at 10:30 PM, Niels Richard Hansen < niels.r.hansen+li...@math.ku.dk> wrote: > Joshua and Luis > > Neither of you is exactly solving the problem as stated, se

Re: [R] Matching a vector with a matrix row

2011-04-22 Thread Niels Richard Hansen
Joshua and Luis Neither of you is exactly solving the problem as stated, see below. Luis, could you clarify if you want rows that are _equal_ to a vector or rows with entries _contained_ in a vector? If m <- matrix(c("A", "B", "C", "B", "A", "A"), 3, 2) LHS <- c("A", "B") then LHS equals the f

Re: [R] Matching a vector with a matrix row

2011-04-21 Thread Joshua Wiley
Hi Felipe, Since matrices are just a vector with dimensions, you could easily use something like this (which at least on my system, is slightly faster): results <- which(Matrix %in% LHS) I'm not sure this is the fastest technique thought. It will return a vector of the positions in "Matrix" tha

[R] Matching a vector with a matrix row

2011-04-21 Thread Luis Felipe Parra
Hello I am trying to compare a vector with a Matrix's rows.The vector has the same length as the number of columns of the matrix, and I would like to find the row numbers where the matrix's row us the same as the given vector. What I am doing at the moment is using apply as follows: apply(Matrix,1