Re: [R] keep the row indexes/names when do aggregate

2008-09-24 Thread Adaikalavan Ramasamy
Not the most elegant solution but here goes. df <- data.frame(g=c("g1","g2","g1","g1","g2"),v=c(1,7,3,2,8)) rownames.which.max <- function(m, col){ w <- which.max( m[ , col] ) return( rownames(m)[w] ) } df.split <-

Re: [R] keep the row indexes/names when do aggregate

2008-09-24 Thread Gabor Grothendieck
Rather than aggregate, use order and duplicated as in this post: https://stat.ethz.ch/pipermail/r-help/2008-September/173139.html On Wed, Sep 24, 2008 at 11:21 AM, zhihuali <[EMAIL PROTECTED]> wrote: > > Hi, R-users, > > If I have a data frame like this: >>x<-data.frame(g=c("g1","g2","g1","g1","g

[R] keep the row indexes/names when do aggregate

2008-09-24 Thread zhihuali
Hi, R-users, If I have a data frame like this: >x<-data.frame(g=c("g1","g2","g1","g1","g2"),v=c(1,7,3,2,8)) g v 1 g1 1 2 g2 7 3 g1 3 4 g1 2 5 g2 8 It contains two groups, g1 and g2. Now for each group I want the max v: > aggregate(x$v,list(g=x$g),max) g x 1 g1 3 2 g2 8 Beautiful. But wh