Re: [R] Subsetting for the ten highest values by group in a dataframe

2012-01-28 Thread Gabor Grothendieck
On Fri, Jan 27, 2012 at 2:26 PM, Sam Albers wrote: > Hello, > > I am looking for a way to subset a data frame by choosing the top ten > maximum values from that dataframe. As well this occurs within some > factor levels. > > ## I've used plyr here but I'm not married to this approach > require(ply

Re: [R] Subsetting for the ten highest values by group in a dataframe

2012-01-28 Thread Hadley Wickham
On Fri, Jan 27, 2012 at 1:26 PM, Sam Albers wrote: > Hello, > > I am looking for a way to subset a data frame by choosing the top ten > maximum values from that dataframe. As well this occurs within some > factor levels. > > ## I've used plyr here but I'm not married to this approach > require(ply

Re: [R] Subsetting for the ten highest values by group in a dataframe

2012-01-27 Thread Phil Spector
Sam - I think that subset is what's throwing you off here -- you need a function that will simply return the 10 rows of each group with the highest values of x: function(dat)dat[order(dat$x,decreasing=TRUE)[1:10],] Then ddply(df,'z',function(dat)dat[order(dat$x,decreasing=TRUE)[1:10],]) sho

[R] Subsetting for the ten highest values by group in a dataframe

2012-01-27 Thread Sam Albers
Hello, I am looking for a way to subset a data frame by choosing the top ten maximum values from that dataframe. As well this occurs within some factor levels. ## I've used plyr here but I'm not married to this approach require(plyr) ## I've created a data.frame with two groups and then a id var