[R] mean
baptiste auguie
baptiste.auguie at gmail.com
Mon Jun 8 14:28:08 CEST 2009
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
More information about the R-help
mailing list