set.seed(1L)
DT <- data.table(A = rep(letters[2:1], each = 4L),
B = rep(1:4, each = 2L),
C = sample(8))
DT2 <-DT[, .(C = cumsum(C)), by =.(A,B)]
DT2[, .(C = tail(C,2)), by = A]
A C
1: b 4
2: b 9
3: a 2
4: a 8
有人可以解释最后一个命令中发生了什么吗?我正在使用tail(C,2)选择2个值,但它给了我4个值?