I have some simple commands looking into totals, means and maximums of a variable whilst another variable is an assigned value:
sum(data[data$var1==1,]$var2) mea
Look at the tables package, read through the vignette for the package shows how to do exactly what you are asking for.
> tabular( ( factor(cyl) + 1) ~ mpg * (sum + mean + max), data=mtcars ) mpg factor(cyl) sum mean max 4 293.3 26.66 33.9 6 138.2 19.74 21.4 8 211.4 15.10 19.2 All 642.9 20.09 33.9