gpt4 book ai didi

r - 以编程方式选择 data.table 中的列名

转载 作者:行者123 更新时间:2023-12-04 11:26:26 24 4
gpt4 key购买 nike

<分区>

我想以编程方式访问 data.table 中名为“X201804_QTY”的列,但我没有成功。也许有人可以帮忙?谢谢。

#test data
library(data.table)
data <- data.table(test = 1:10, X201804_QTY = 11:20)

#create column name programmatically
col <- paste0(make.names(format(as.Date("2018-04-30"), "%Y%m")),"_QTY")

#not working
data[, .(test, col)]
data[, .(test, col), which = FALSE]
data[, c("test", col)]
data[, c("test", col), which = FALSE]

data.table version: 1.10.4-3

24 4 0