From a data.table d such as for example
d
require(data.table) d = data.table(a = 1:4, b = 11:14, c = 21:24, group = c(1,1,2,2))
d[, lapply(.SD, sum), by = group, .SDcols = varsToSum] group a b 1: 1 3 23 2: 2 7 27