[R] How to delete a duplicate observation
    Sundar Dorai-Raj 
    sundar.dorai-raj at pdf.com
       
    Thu Sep 13 20:42:18 CEST 2007
    
    
  
nuyaying said the following on 9/13/2007 9:50 AM:
> 
> I have a data set with 3 variables V1, V2, V3.  If there are 2 data points
> have the same values on both V1 and V2,  I want to delete one of them which
> has smaller V3 value.    i.e., in the data below, I want to delete 
> the first observation.  How can I do that ?    Thanks in advance!      
> 
> V1  V2  V3
> 3    3     1
> 3    3     4
> 
How about:
## some sample data
d <- read.table(textConnection("V1 V2 V3
3 3 2
3 3 4
3 3 1
3 2 1
3 2 5"), header = TRUE)
## the code
d <- d[rev(do.call("order", d)), ]
d <- d[!duplicated(d[1:2]), ]
d
HTH,
--sundar
    
    
More information about the R-help
mailing list