R's data.table
包提供基于键的值的快速子集化。
因此,例如:
set.seed(1342)
df1 <- data.table(group = gl(10, 10, labels = letters[1:10]),
value = sample(1:100))
setkey(df1, group)
df1["a"]
将返回 df1 中 group == "a" 的所有行。
如果我想要所有行怎么办df1
where group != "a"
。是否有一个简洁的语法使用data.table
?
我想你回答了你自己的问题:
> nrow(df1[group != "a"])
[1] 90
> table(df1[group != "a", group])
a b c d e f g h i j
0 10 10 10 10 10 10 10 10 10
对我来说似乎很简洁?
马修编辑:根据评论,这是矢量扫描。有一个不加入成语 here and here, and 功能请求#1384让事情变得更容易。
EDIT: 功能请求#1384在data.table 1.8.3中实现
df1[!'a']
# and to avoid the character-to-factor coercion warning in this example (where
# the key column happens to be a factor) :
df1[!J(factor('a'))]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)