在数据表中选择连续和非连续的列,就像在 dplyr 的 group_by 中一样

问题描述 投票:0回答:0

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)]

有办法吗?

r dplyr data.table tidy
© www.soinside.com 2019 - 2024. All rights reserved.