[R] How can I return rows from a data frame with maximum value by factor?

Greg Snow Greg.Snow at imail.org
Wed Mar 17 21:57:27 CET 2010

For future reference you may want to look at the plyr package, or even the sapply and aggregate functions and possibly simpler ways to do what you did below.

Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Nick Ackerman
> Sent: Wednesday, March 17, 2010 11:45 AM
> To: r-help at r-project.org
> Subject: Re: [R] How can I return rows from a data frame with maximum
> value by factor?
> Solved my own question by looking at some other threads. For those who
> may be
> intersted, here was the solution to my problem.
> do.call(rbind,lapply(split(data.frame,FISH_ID),function(x)x[which.max(x
> $DATE_TIME),]))
> --
> View this message in context: http://n4.nabble.com/How-can-I-return-
> rows-from-a-data-frame-with-maximum-value-by-factor-
> tp1596777p1596853.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at 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.

More information about the R-help mailing list