【发布时间】:2012-05-21 18:37:16
【问题描述】:
我正在尝试学习R 中的data.table 包。我有一个名为DT1 的数据表和一个数据框DF1,我想根据逻辑条件(析取)对一些实例进行子集化。这是我现在的代码:
DF1[DF1$c1==0 | DF1$c2==1,] #the data.frame way with the data.frame DF1
DT1[DT1$c1==0 | DT1$c2==1,] #the data.frame way with the data.table DT1
在"Introduction to the data.table package in R" 的第 5 页上,作者给出了一个类似的例子,但带有一个连词(在上面的第二行中将| 替换为&)并指出data.table 包的使用不当。他建议这样做:
setkey(DT1,c1,c2)
DT1[J(0,1)]
所以,我的问题是:如何使用data.table 包语法编写析取条件?这是滥用我的第二行DT1[DT1$c1==0 | DT1$c2==1,] 吗?是否有与J 等效但用于析取的方法?
【问题讨论】:
标签: r data.table