【发布时间】:2016-11-16 20:24:33
【问题描述】:
这可能有点奇怪,但我在使用 data.table 的函数中使用其参数进行过滤时经常遇到这种情况。
假设您有一个变量,您想将其值与data.table 的列进行比较并进行过滤。如果变量名与列名相同怎么办?
示例和我尝试过的事情:
DT <- data.table(mtcars)
cyl <- 4
# intended: filter rows where column "cyl" equals the value of variable cyl
# this does not work
DT[cyl == (cyl)]
# this does not work either
DT[cyl == `cyl`]
【问题讨论】:
标签: r data.table