Hi:

Here are a couple of ways using the doBy and plyr packages:

library(doBy)
library(plyr)

# doBy:
subsetBy(~ wool + tension, subset = breaks == max(breaks), data =
warpbreaks)

    breaks wool tension
A|H     43    A       H
A|L     70    A       L
A|M     36    A       M
B|H     28    B       H
B|L     44    B       L
B|M     42    B       M

# plyr
ddply(warpbreaks, .(wool, tension), subset, breaks == max(breaks))

  breaks wool tension
1     70    A       L
2     36    A       M
3     43    A       H
4     44    B       L
5     42    B       M
6     28    B       H

HTH,
Dennis

On Tue, May 18, 2010 at 1:58 AM, Tim Van den Bulcke <
vandenbulcketim@gmail.com> wrote:

> Hi,
>
>
> I'd like to select one row in a data frame per subset which is maximal for
> a
> particular value. I'm pretty close to the solution in the sense that I can
> easily select the maximal values per subset using "aggregate", but I can't
> really figure out how to select the rows in the original data frame that
> are
> associated with these maximal values.
>
>
> library(stats)
> # this returns the list with maximal values for breaks per wool/tension
> subset
> maxValues = aggregate(warpbreaks$breaks, list(wool = wool, tension =
> tension), max)
>
> # now i'd like the subset of the rows in warpbreaks that are associated
> with
> these maximal values
>
>
>
> Thank you in advance!
>
> Tim.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

