Try aggregate:
aggregate(table[2:3], table[1], mean)
On 6/17/07, Andrew Yee <[EMAIL PROTECTED]> wrote:
> I have the following data.frame:
>
> index <- c("a","a","b","b","b")
> alpha <- c(1,2,3,4,5)
> beta <- c(2,3,4,5,6)
> table <-data.frame(index,alpha,beta)
>
> I'm now interested in getting means of alpha and beta for each of the
> index values and do a tapply() for each of the columns, e.g.
>
> means.alpha <- tapply(table$alpha, index,mean)
> means.beta <- tapply(table$beta,index,mean)
>
> but as one tapply function, something like
>
> tapply(table[2:3], index, mean), but this clearly doesnt' work.
>
> Suggestions?
>
> Thanks,
> Andrew
>
> ______________________________________________
> [email protected] 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.
>
______________________________________________
[email protected] 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.