nuyaying wrote: > I have a data set with 3 variables V1, V2, V3. If there are 2 data points > have the same values on both V1 and V2, I want to delete one of them which > has smaller V3 value. i.e., in the data below, I want to delete > the first observation. How can I do that ? Thanks in advance! > > V1 V2 V3 > 3 3 1 > 3 3 4 > > Tricky one... I think something like this should work:
l <- split(d$V3, list(d$V1,d$V2)) ixl <- lapply(l, function(x) { if ((n <- nrow(x)) == 2) seq_len(n) != which.min(x) else rep(TRUE, n) }) ix <- unsplit(ixl, list(d$V1,d$V2)) d[ix,] -- O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ R-help@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.