group_by 的好处是它允许你用 : 选择连续的列,然后如果有不连续的列你可以用 "," 分隔。但是,您似乎不能在 data.table 中这样做
library(data.table)
# create a sample data.table
dt <- data.table(a = c("A", "A", "B", "B"), b = c(1, 2, 3, 4), c = c(5, 6, 7, 8), d = c(9, 10, 11, 12))
# group by columns a, b, c, and d
dt[, .(sum(b)), by = .(a, c:d)]
有办法吗?