[R] Better way to create tables of mean & standard deviations
hadley wickham
h.wickham at gmail.com
Tue Nov 7 16:07:38 CET 2006
> With the reshape package, I'd do it like this:
>
> df <- data.frame(LAB = rep(1:8, each=60), BATCH = rep(c(1,2), 240), Y
> =rnorm(480))
> dfm <- melt(df, measured="Y")
Should be
dfm <- melt(df, measure.var="Y")
(thanks to Chuck for pointing that out)
>
> cast(dfm, LAB ~ ., c(mean, sd, length))
> cast(dfm, LAB + BATCH ~ ., c(mean, sd, length))
> cast(dfm, LAB + BATCH ~ ., c(mean, sd, length), margins=T)
>
> Regards,
>
> Hadley
>
More information about the R-help
mailing list