Re: [R] how to find a row index in a matrix or a data frame ?

2010-11-25 Thread Gabor Grothendieck
On Thu, Nov 25, 2010 at 4:59 AM, Luedde, Mirko wrote: > Dear all, > > this looks pretty much a standard problem, but I couldn't find a > satisfying and understandable solution. > > (A) Given a data frame (or matrix), e.g. > >      x <- data.frame(A=c(1, 2, 2), B=c(4, 5, 5)) > >    and a row of thi

Re: [R] how to find a row index in a matrix or a data frame ?

2010-11-25 Thread Henrique Dallazuanna
Try this: which((apply(x, 1, toString) %in% toString(r))) On Thu, Nov 25, 2010 at 7:59 AM, Luedde, Mirko wrote: > Dear all, > > this looks pretty much a standard problem, but I couldn't find a > satisfying and understandable solution. > > (A) Given a data frame (or matrix), e.g. > > x <- d

Re: [R] how to find a row index in a matrix or a data frame ?

2010-11-25 Thread Luedde, Mirko
: Luedde, Mirko Cc: r-help@r-project.org Betreff: Re: [R] how to find a row index in a matrix or a data frame ? rows <- which(apply(mapply(x, r, FUN="=="), MARGIN=1, FUN=all)); /H On Thu, Nov 25, 2010 at 1:59 AM, Luedde, Mirko wrote: > Dear all, > > this looks pretty much a s

Re: [R] how to find a row index in a matrix or a data frame ?

2010-11-25 Thread Henrik Bengtsson
rows <- which(apply(mapply(x, r, FUN="=="), MARGIN=1, FUN=all)); /H On Thu, Nov 25, 2010 at 1:59 AM, Luedde, Mirko wrote: > Dear all, > > this looks pretty much a standard problem, but I couldn't find a > satisfying and understandable solution. > > (A) Given a data frame (or matrix), e.g. > >  

Re: [R] how to find a row index in a matrix or a data frame ?

2010-11-25 Thread Eric Lecoutre
Mirko, Here is a solution - I am sure other R mentors would find a more efficient one > x <- data.frame(A=c(1, 2, 2), B=c(4, 5, 5)) > x <- rbind(x,x) > r <- c(2,5) > > (rowfind=apply(x,1,FUN=function(row,add){isTRUE(all.equal(row,add,check.attributes = FALSE))},add=r)) 1 2 3 4 5 6 FALSE TR

[R] how to find a row index in a matrix or a data frame ?

2010-11-25 Thread Luedde, Mirko
Dear all, this looks pretty much a standard problem, but I couldn't find a satisfying and understandable solution. (A) Given a data frame (or matrix), e.g. x <- data.frame(A=c(1, 2, 2), B=c(4, 5, 5)) and a row of this data frame, e.g. r <- c(2, 5) I need to find one row