Re: [R] how to get the mean of each group?

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Sun 19 Jun 2005 - 23:31:25 EST

ronggui wrote:
> i have the data x.1
>
>

>>x.1 <- data.frame(income=runif(100)*10000,

>
> + edu=sample(c('hs','col','none'),100,T),y=rnorm(100)*100)
>
> and i want to get :
>
> income y
> col 5526.726 -11.00956
> hs 4196.036 -10.03861
> none 4308.111 -28.69549
>
> 5526.726 is the mean income for col, 4196.036 is the mean income for hs......
>
>
>

See ?aggregate, ?by and ?tapply

E.g.:
  aggregate(x.1[,c(1,3)], list(x.1[,2]), mean)

Uwe Liggges



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jun 19 23:34:18 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:51 EST