[R] how to select rows per subset in a data frame that are max. w.r.t. a column

Ivan Calandra ivan.calandra at uni-hamburg.de
Tue May 18 11:12:07 CEST 2010


Hi,

Maybe it's just me but I don't understand what you're trying to do.
Isn't maxValues what you need?
Providing a reproducible example with your data (using the function 
dput), the desired output, and the code you've tried would really help!

Ivan

Le 5/18/2010 10:58, Tim Van den Bulcke a écrit :
> 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 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.
>
>    

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php



More information about the R-help mailing list