【发布时间】:2016-10-10 08:50:41
【问题描述】:
我想通过 data.table 中的 list 列来聚合一些列。但是,我想避免使用引号之外的列名(即在by = .(desiredColumn1, desiredColumn2) 中)。我很高兴使用列名或列索引。例如:
library(data.table)
x = as.data.table(iris)
x[, sum(Sepal.Width), by = .(Sepal.Length, Species)] # I want to avoid doing this
x[, sum("Sepal.Width"), by = .("Sepal.Length", "Species"), with = FALSE] # this does not work
x[, sum("Sepal.Width"), by = .(1, 5), with = FALSE]
关于如何做到这一点的任何想法?
【问题讨论】:
标签: r data.table aggregate