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
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
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
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
4 matches
Mail list logo