Let's keep this simple. I have the following DT:
library(data.table)
test <- setDT(data.frame(a=c(1,2,2,1,3,3,3,4,4,4),b=c(1:9,9)))
test[a == 4,sum(b),b]
gives:
b V1
1: 8 8
2: 9 9
but why? Should the sum of the second row not be equal to 18? If I use first:
test[a == 4]
we get
a b
1: 4 8
2: 4 9
3: 4 9
so clearly, the sum of b by the second b group should be 18. What am I missing? Note: I am not saying that command makes much sense, but I am trying to understand it at this time.