[R] More elegant way of excluding rows with equal values in any 2	columns?
    Erik Iverson 
    eiverson at NMDP.ORG
       
    Mon Sep 21 20:55:29 CEST 2009
    
    
  
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 a value is equal in 2 or more rows, i.e., duplicated, then the following should work, assuming index can be changed to a matrix for apply ... 
t3 <- index[apply(index, 1, function(x) all(!duplicated(x))),]
    
    
More information about the R-help
mailing list