I am using ddply in R and I break the data in two different ways, but I want a subtotal of both. This is the function I am using
require(plyr)
dfx <- data.frame(
group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
sex = sample(c("M", "F"), size = 29, replace = TRUE),
age = runif(n = 29, min = 18, max = 54)
)
# Note the use of the '.' function to allow
# group and sex to be used without quoting
ddply(dfx, .(group, sex), summarize,
mean = round(mean(age), 2),
sd = round(sd(age), 2))
I also want to summarize (mean, sd) by group and (mean,sd) summary of the entire data set. Is there a way to include this in the same ddply?