Ddply's successor, dplyr, can do this very easily using group_by() and summarise_each() , without having to contact anything:
df <- data.frame(site = c("Alberta", "Alberta", "Alberta", "Nunavut", "Nunavut", "Nunavut", "Alberta", "Alberta", "Alberta", "Nunavut", "Nunavut", "Nunavut"), block = c(1, 2, 4, 1, 2, 3, 5, 4, 5, 5, 5, 4), plot = c(2, 5, 10, 1, 4, 8, 13, 12, 15, 14, 13, 11), rep = c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3), name = c("A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B"), weight = c(43, 46, 49, 49, 51, 52, 55, 55, 56, 57, 58, 59), height = c(139, 139, 136, 136, 135, 133, 132, 125, 120, 119, 119, 118), dtf = c(54, 46, 54, 59, 50, 56, 50, 46, 46, 54, 55, 51)) library(dplyr) df.summary <- df %>% group_by(site, name) %>% summarise_each(funs(sum, min, max, mean, sd), weight, height, dtf)
The result is a data frame:
> df.summary Source: local data frame [4 x 17] Groups: site site name weight_length height_length dtf_length weight_min height_min dtf_min 1 Alberta A 3 3 3 43 136 46 2 Alberta B 3 3 3 55 120 46 3 Nunavut A 3 3 3 49 133 50 4 Nunavut B 3 3 3 57 118 51 Variables not shown: weight_max (dbl), height_max (dbl), dtf_max (dbl), weight_mean (dbl), height_mean (dbl), dtf_mean (dbl), weight_sd (dbl), height_sd (dbl), dtf_sd (dbl)
You can pass any function that you want to use funs() inside summarise_each , so if you need a column for standard errors, first execute the function:
se <- function(x) { N <- sum(!is.na(x[1])) return(sd / sqrt(N)) }
And skip it: summarise_each(funs(sum, min, max, mean, sd, se)...)