作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 data.table
像这样的结构(除了我的真的很大):
dt <- data.table(x=1:5, y=3:7, key='x')
x
的变量查找该结构中的行(注意 - 与
dt
的键名相同):
x <- 3:4
dt2 <- dt[ J(x) ]
dt2
# x y
# 1: 1 3
# 2: 2 4
# 3: 3 5
# 4: 4 6
# 5: 5 7
with
[.data.table
的论据,但这仅适用于
j
参数,而不是
i
争论。
i
是否有类似的东西?争论?
dt
中列名的完整列表时,这样的事情就会很方便。 ,避免冲突。
最佳答案
在 1.8.2 的新闻中有一条建议 ..()
语法将在某个时候添加,允许这样做
New DT[.(...)] syntax (in the style of package plyr) is identical to DT[list(...)], DT[J(...)] and DT[data.table(...)]. We plan to add ..(), too, so that .() and ..() are analogous to the file system's ./ and ../; i.e., .() evaluates within the frame of DT and ..() in the parent scope.
get
从合适的环境
dt[J(get('x', envir = parent.frame(3)))]
## x y
## 1: 3 5
## 2: 4 6
eval
全程调用
list(x)
或
J(x)
dt[eval(list(x))]
dt[eval(J(x))]
dt[eval(.(x))]
关于r - 在没有 'with' 的情况下对 data.table 进行键控查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15102068/
我是一名优秀的程序员,十分优秀!