Q:

summary table with total whilst controlling for value on one variable?

I've used function summary(data[data$var1==5,]) to get a summary of observations while controlling var1 at 5 (or whatever).
However, I also need a total for a particular var2 as well, and I'm unsure how to go about coding that in here whilst keeping the variable that I want controlled at 5 (or 1, or whatever).
I'm quite happy writing a second line looking for the total of var2 whilst controlling var1.  Any help would be appreciated, thanks.

A:

Are you looking for something like this?
sum(data[data$var1==5,]$var2) 

or (without the comma)
sum(data$var2[data$var1==5]) 

