Anybody have any bright ideas on how to do multiple aggregations such as sum and mean with arithmetic on the left hand side of the formula, something like this:
aggregate(A+B ~ C, data=D, FUN=c(sum, mean))
I expect a 3 column result with C, mean(A+B) and sum(A+B).
I've looked at summaryBy from the 'doBy' package but it fails with the arithmetic.
The closest I've found is to create a custom function taking a param and then applying the 2 aggregation functions within it, however, the result is still a bit messy to work with as there are 2 columns, the second containing a list with both aggregations.
aggregate(A+B ~ C, data = D, FUN=function(x) c(s=sum(x), m=mean(x)))
It's tedious, verbose and more computationally expensive doing two aggregations across the same data and then merging those aggregations.