Hi: Here's another approach using the plyr package:
# Write a function that takes a data frame as input and outputs a data frame f <- function(df) df[which.max(df$Fish), ] ddply(x, 'Bin', f) Bin Depth Fish 1 1 8 24 2 2 8 21 3 3 12 33 HTH, Dennis On Tue, Jun 7, 2011 at 3:32 PM, SamiC <s.cox...@aberdeen.ac.uk> wrote: > So I have figured out how to do it via a series of loops and conditions, but > i am thinking there must be a quicker way to do it. > > an example. > > Bin Depth Fish to: Bin Depth MaxFish > 1 4 2 1 8 24 > 1 8 24 2 8 21 > 1 12 4 3 12 33 > 2 4 3 > 2 8 21 > 2 12 2 > 3 4 12 > 3 8 2 > 3 12 33 > > -- > View this message in context: > http://r.789695.n4.nabble.com/Sorting-Dataframes-tp3580075p3581046.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. > ______________________________________________ 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.