Re: [R] How to delete duplicate cases?

From: Patrizio Frederic <frederic.patrizio_at_gmail.com>
Date: Thu, 24 Jul 2008 16:34:37 +0200

this works

cno 	= c(rep(1342,times=3),rep(2568,times=2))
rank	= c(.23,.14,.56,.15,.89)

df1	= data.frame(cno,rank)[order(cno,rank),]

cnou	= unique(cno)
ind	= match(cno,cnou)
where	= tapply(rank,ind,length)
where	= cumsum(as.numeric(where))

df1[where,]

regards,

PF

2008/7/24 Daniel Wagner <danieljm1976_at_yahoo.com>:
> 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.
>
>



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. Received on Thu 24 Jul 2008 - 15:16:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jul 2008 - 16:32:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive