I am fairly new to data.table. I still struggle with things that could be easily done with dataframes. I have succededed adding up the rows of several columns but I wonder if there is a less verbose way of going about it.
Data:
set.seed(85719)
DT <- data.table(
t1 = rbinom(100,1,0.7),
t2 = rbinom(100,1,0.1),
a1 = rbinom(100,1,0.99),
a2 = rbinom(100,1,0.31),
l = letters,
L = LETTERS
)
This is what I did (I have to admit I don't know what .() does and its hard to google just symbols):
DT[,.(
"sumt1"=sum(t1),
"sumt2"=sum(t2),
"suma1"=sum(a1),
"suma2"=sum(a2)
)]
and get what I want:
sumt1 sumt2 suma1 suma2
1: 70 14 98 32
I am just wondering if there is a simpler way to obtain thet sum of several columns.