I also tried using Jim's code, but it doesn't work as expected with my real dataset. This is what I did:
Best.na <- do.call(rbind, lapply(split(x, x$A), function(.grp){ best <- which.min(apply(.grp, 1, function(a) sum(is.na(a)))) .grp[best, ] })) df.split <- split(Best.na, Best.na$id) Best.date <- lapply(df.split, function(x){ # Select by given criterion y <- x[which(max(x$A) == x$A),] y }) Best.date <- do.call(rbind, Best.date) Thank you again for your help. -- View this message in context: http://r.789695.n4.nabble.com/Choose-between-duplicated-rows-tp4557833p4559792.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.