[R] which duplicated rows to delete

Søren Merser merser at image.dk
Mon Oct 30 11:11:01 CET 2006


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



More information about the R-help mailing list