Skip to content
Prev 175432 / 398502 Next

which rows are duplicates?

At 05:07 30/03/2009, Aaron M. Swoboda wrote:
Does this do what you want?
 > x <- c(1,3,1)
 > y <- c(2,4,2)
 > z <- c(3,4,3)
 > data <- data.frame(x,y,z)
 > data.u <- unique(data)
 > data.u
   x y z
1 1 2 3
2 3 4 4
 > data.u <- cbind(data.u, set = 1:nrow(data.u))
 > merge(data, data.u)
   x y z set
1 1 2 3   1
2 1 2 3   1
3 3 4 4   2

You need to do a bit more work to get them back into the original row 
order if that is essential.
Michael Dewey
http://www.aghmed.fsnet.co.uk