Re: [R] which duplicated rows to delete

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 30 Oct 2006 - 10:46:39 GMT

Try this. The first line breaks it up into lists and the second line drops any list that is not greater than 1 in length:

out <- tapply(seq(x), x, function(x)x)
out[sapply(out, length) > 1]

On 10/30/06, Søren Merser <merser@image.dk> wrote:
> Hi
> Say I've this vector with several duplicates
> >x<-c(1,2,3,4,2,6,2,8,2,3)
>
> >which(duplicated(x))
> [1] 5 7 9 10 11
>
> But what I realy want is somthing like:
> List({2,5,7}, {3,10}, ...)
>
> Then from each sublist I can specify which of the duplicate items to drop
>
> res<-NULL
> for(vec in myDuplicateList)
> res<-rbind(res, subset(data[vec,], myCrit))
>
> I'll get some of the way by sorting my original data appropriately, as it's
> the second and following rows that are 'marked' as duplicates, but that's
> not quite enough
>
> Hope for some hints
> Kind regards Søren
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 Tue Oct 31 00:06:06 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 30 Oct 2006 - 15:30:14 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.