Skip to content
Prev 176371 / 398503 Next

SUM,COUNT,AVG

Jun Shen:
summarize() *does* work with multiple columns from data frames, but the 
function you use must be able to do column-wise calculations. Example:

with(iris, summarize(iris[1:4], Species, colSums, stat.name=NULL))

If there weren?t a ?colSums? function, you could easily accomplish the same 
thing by using apply on the ?sum? function:

with(iris, summarize(iris[1:4], Species, function(x) apply(x,2,sum), 
stat.name=NULL))