[R] group means

Roger Peng rpeng at stat.ucla.edu
Fri Feb 21 00:04:04 CET 2003


You could try using `aggregate', e.g.

df <- data.frame(a = rnorm(10, 1), b = rnorm(10, 2))
grps <- rep(1:2, each = 5)
aggregate(df, list(grps), mean)

-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng

On Thu, 20 Feb 2003, Sundar Dorai-Raj wrote:

> 
> 
> Jeremy Z Butler wrote:
> > Hi,
> > Any hints on how I would generate the means of each 5 number group in a 
> > column of numbers in data.frame form. i.e. get mean of first five in 
> > column and then mean of second five in column etc. etc.
> > 
> > 1   3.4
> > 2   6.0
> > 3   2.5
> > 4   7.5
> > 5   1.8
> > 6   4.2
> > 7   6.4
> > 8   5.7
> > 9   17.2
> > 10  13.5
> > 
> 
> See ?running in package:gregmisc.
> 
> Sundar
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list