On Fri, Oct 2, 2009 at 4:24 AM, jim holtman <jholt...@gmail.com> wrote: > try this: > >> x <- read.table(textConnection("x1 x2 x3 > + A 1 1.5 > + B 2 0.9 > + B 3 2.7 > + C 7 1.8 > + D 7 1.3"), header=TRUE) >> closeAllConnections() >> do.call(rbind, lapply(split(seq(nrow(x)), x$x1), function(.row){ > + x[.row[which.min(x$x2[.row])],] > + })) > x1 x2 x3 > A A 1 1.5 > B B 2 0.9 > C C 7 1.8 > D D 7 1.3 >>
Or, using plyr and subset library(plyr) ddply(x, "x1", subset, x2 == min(x2)) Hadley -- http://had.co.nz/ ______________________________________________ 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.