[R] variation of the aggregate function

2010-08-13 Thread Eva Nordstrom
Is there a more efficient/elegant way to obtain the result z below.

a - c('pink','pink','blue','blue','gold','gold')
b - c(5,8,9,12,7,4)
agg - aggregate(x=b,by=list(a), FUN='mean')
m - match(a, agg[,1])
z - agg[m,2]
z



  
[[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.


Re: [R] variation of the aggregate function

2010-08-13 Thread Gabor Grothendieck
On Fri, Aug 13, 2010 at 12:26 PM, Eva Nordstrom eva.nordst...@yahoo.com wrote:
 Is there a more efficient/elegant way to obtain the result z below.

 a - c('pink','pink','blue','blue','gold','gold')
 b - c(5,8,9,12,7,4)
 agg - aggregate(x=b,by=list(a), FUN='mean')
 m - match(a, agg[,1])
 z - agg[m,2]
 z


Try:

   ave(b, a)

__
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.