Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Dimitri Liakhovitski
Thanks a lot everyone - it's been extremely helpful! Dimitri On Mon, Sep 21, 2009 at 3:16 PM, Jorge Ivan Velez wrote: > > Hi Dimitri, > Try also either > index[apply(index, 1, function( x ) length( unique( x ) ) == 4 ),] > or > # install.packages('e1071') > require(e1071) > permutations(4) > HTH,

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Jorge Ivan Velez
Hi Dimitri, Try also either index[apply(index, 1, function( x ) length( unique( x ) ) == 4 ),] or # install.packages('e1071') require(e1071) permutations(4) HTH, Jorge On Mon, Sep 21, 2009 at 2:14 PM, Dimitri Liakhovitski <> wrote: > Hello, dear R-ers! > > I built a data frame "grid" (below)

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Erik Iverson
> > You could also replace "!duplicated" in my function with "unique" ... > It turns out you can't, of course :). __ 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.o

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread David Winsemius
On Sep 21, 2009, at 2:14 PM, Dimitri Liakhovitski wrote: Hello, dear R-ers! I built a data frame "grid" (below) with 4 columns. I want to exclude all rows that have equal values in ANY 2 columns. Here is how I am doing it: index<-expand.grid(1:4,1:4,1:4,1:4) dim(index) # Deleting rows that ha

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Erik Iverson
could also replace "!duplicated" in my function with "unique" ... Erik > -Original Message- > From: Dimitri Liakhovitski [mailto:ld7...@gmail.com] > Sent: Monday, September 21, 2009 2:02 PM > To: Erik Iverson > Cc: R-Help List > Subject: Re: [R] M

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Dimitri Liakhovitski
Thank you very much, both Dimitris and Erik. Erik - you are right, I was trying to remove any duplication (i.e., if there are the same values in 2 or 3 or 4 columns). And it looks like that's what your solution does. But doesn't it do the same thing as Dimitris' solution? Dimitri On Mon, Sep 21,

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Erik Iverson
Hello, Do you mean exactly any 2 columns. What if the value is equal in more than 2 columns? > > I built a data frame "grid" (below) with 4 columns. I want to exclude > all rows that have equal values in ANY 2 columns. Here is how I am > doing it: > > index<-expand.grid(1:4,1:4,1:4,1:4) If

Re: [R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Dimitris Rizopoulos
one way is the following: index <- expand.grid(1:4, 1:4, 1:4, 1:4) mat <- data.matrix(index) keep <- apply(mat, 1, function (x, d) length(unique(x)) == d, d = ncol(mat)) index[keep, ] I hope it helps. Best, Dimitris Dimitri Liakhovitski wrote: Hello, dear R-ers! I built a data frame "

[R] More elegant way of excluding rows with equal values in any 2 columns?

2009-09-21 Thread Dimitri Liakhovitski
Hello, dear R-ers! I built a data frame "grid" (below) with 4 columns. I want to exclude all rows that have equal values in ANY 2 columns. Here is how I am doing it: index<-expand.grid(1:4,1:4,1:4,1:4) dim(index) # Deleting rows that have identical values in any two columns (1 line of code): inde