Ben Bolker wrote:
amor Gandhi wrote:
Hi,
I have gote the following data
x1 <- c(rep(1,6),rep(4,7),rep(6,10))
x2 <- rnorm(length(x1),6,1)
data <- data.frame(x1,x2)
and I would like to compute the mean of the x2 for each individual of x1,
i. e. x1=1,4 and 6?
You'll probably get seven answers to this, but:
tapply(x2,list(x1),mean)
alternatives[2:3] might read,
library(doBy)
summaryBy(.~x1, d, FUN=mean)
library(plyr)
ddply(d, .(x1), .fun=mean)
HTH,
baptiste
______________________________________________
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.