I would have guessed that
fun.aggregate=function(x) { c(mean(x), median(x))}
... might work. Untested in the absence of a working example.
Unfortunately the help page suggests that may not work: "This function
should take a vector of numbers and return a single summary statistic."
Maybe you could just use aggregate in base R:
ag <- aggregate(len ~ dose, data = ToothGrowth, FUN=function(x){c(mn
=mean(x), mdn= median(x))})
> ag
dose len.mn len.mdn
1 0.5 10.605 9.850
2 1.0 19.735 19.250
3 2.0 26.100 25.950
> print (ap2)
>
> --
> You received this message because you are subscribed to the Google
> Groups "manipulatr" group.
> To post to this group, send email to manip...@googlegroups.com.
> To unsubscribe from this group, send email to manipulatr+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/manipulatr?hl=en
> .
>
David Winsemius, MD
West Hartford, CT
No - you need to use ddply from the plyr package instead:
> ap2 <- dcast(ap1, subject + Group ~ Length + Complexity + variable,
> fun.aggregate = mean)
ddply(ap1, c("subject", "Group", "Length", "Complexity"), summarise,
mean = mean(variable),
median = median(variable)
It's possible this might be easier to do in the tables package
(http://cran.r-project.org/web/packages/tables/index.html), since it
looks like you're interested in creating a table for display, rather
than a dataset for further analysis.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/