Submitted by: Arun ; Assigned to: Nobody; R-Forge link
require(data.table)
DT <- data.table(x=c(1,2,2,3,3,3), y=10:15)
DT[, print(list(list(.I))), by=x] ## prints fine.
# [[1]]
# [[1]][[1]]
# [1] 1
#
# [[1]]
# [[1]][[1]]
# [1] 2 3
#
# [[1]]
# [[1]][[1]]
# [1] 4 5 6
#
# Empty data.table (0 rows) of 1 col: x
DT[, list(list(.I)), by=x] ## all points to last grouping variable
# x V1
#1: 1 4,5,6
#2: 2 4,5,6
#3: 3 4,5,6
The issue goes away if . is wrapped with I(.) or any other function for that matter.
## works fine.
DT[, list(list(I(.I))), by=x]
DT[, list(list(sum(y))), by=x]