[R] How to delete duplicate cases?

Erik Iverson iverson at biostat.wisc.edu
Thu Jul 24 16:21:04 CEST 2008


Daniel -

First, use order() to arrange the data.frame into an appropriate format.

Then, use duplicated() with the negation operator to get rid of the 
duplicated values.



Daniel Wagner wrote:
> Dear R users,
> Â 
> I have a dataframe with lot of duplicate cases and I want to delete duplicate ones which have low rank and keep that case which has highest rank.
> e.g
> Â 
>> df1
>   cno      rank
> 1Â  1342Â Â Â  0.23
> 2Â  1342Â Â Â  0.14
> 3Â  1342Â Â Â  0.56
> 4Â Â 2568Â Â Â  0.15
> 5Â  2568Â Â Â  0.89
> Â 
> so I want to keep 3rd and 5th  cases with highest rank (0.56 & 0.89) and delete rest of the duplicate cases.
> Could somebody help me?
> Â 
> Regards
> Â 
> Daniel
> Amsterdam
> Â 
> Â 
> Â 
> Â 
> Â 
> Â 
> Â 
> Â 
> 
> Send instant messages to your online friends http://uk.messenger.yahoo.com 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list