Re: [R] match rows of R

2013-06-26 Thread arun
  0.312   1.076 identical(res,res2) #[1] TRUE A.K. - Original Message - From: arun To: Sachinthaka Abeywardana Cc: R help Sent: Wednesday, June 26, 2013 3:26 PM Subject: Re: [R] match rows of R Hi, Try:  roweqv<- function(m,v) which(!is.na(match(interaction(as.data.fr

Re: [R] match rows of R

2013-06-26 Thread arun
  12    4 #[3,]   10   12    4 #[4,]   10   12    4 #[5,]   10   12    4 #[6,]   10   12    4 v2<- c(20,5,4) roweqv(m1,v2) #integer(0) A.K. - Original Message - From: Sachinthaka Abeywardana To: "r-help@r-project.org" Cc: Sent: Wednesday, June 26, 2013 4:03 AM Subject: [R] m

Re: [R] match rows of R

2013-06-26 Thread Berend Hasselman
On 26-06-2013, at 10:30, Yuliya Matveyeva wrote: > I suggest using vectorization : > > find_row <- function(m,v) { which(!(abs(rowSums(m - rep(v, each = nrow(m))) > )) > 0) } > > The function matroweqv mentioned above would give any row with the first > element equal to the first element in ve

Re: [R] match rows of R

2013-06-26 Thread Yuliya Matveyeva
I suggest using vectorization : find_row <- function(m,v) { which(!(abs(rowSums(m - rep(v, each = nrow(m))) )) > 0) } The function matroweqv mentioned above would give any row with the first element equal to the first element in vector v. The function find_row matches each row of the matrix as a

Re: [R] match rows of R

2013-06-26 Thread Berend Hasselman
On 26-06-2013, at 10:03, Sachinthaka Abeywardana wrote: > Hi all, > > What would be an efficient way to match rows of a matrix to a vector? > > ex: > > m<-matrix(1:9, nrow=3) > > m [,1] [,2] [,3] > [1,]147 > [2,]258 > [3,]369 > >

[R] match rows of R

2013-06-26 Thread Sachinthaka Abeywardana
Hi all, What would be an efficient way to match rows of a matrix to a vector? ex: m<-matrix(1:9, nrow=3) m [,1] [,2] [,3] [1,]147 [2,]258 [3,]369 # which(m==c(2,5,8))# I want this to return 2 ##