Yes you absolutely can!
However, a little caution when you use function sum() and so happen to have NAs in you variables, It won't not but worry not there is just one optional argument you need to use --> sum(varname, na.rm=T) . ; na.rm- stands for REMOVE NAs and by default its FALSE
You can read more about this and much more in the help window.
Wish you the best !