R 抗子集设置的magic data.table
我的一位同事发送了以下R 抗子集设置的magic data.table,r,data.table,R,Data.table,我的一位同事发送了以下数据。表(来自CRAN的1.9.4版): 但由于某些原因,它不能被类型==“current”作为子集: > w[type=='current',] Empty data.table (0 rows) of 2 cols: type,value 使用get函数可解决此问题: > w[get('type')=='current',] type value 1: current 10 从data.table中删除索引的操作如下: x <-
数据。表(来自CRAN的1.9.4版):
但由于某些原因,它不能被类型==“current”
作为子集:
> w[type=='current',]
Empty data.table (0 rows) of 2 cols: type,value
使用get
函数可解决此问题:
> w[get('type')=='current',]
type value
1: current 10
从data.table中删除索引的操作如下:
x <- structure(
list(
type = c("current", "prior"),
value = c(10, 20)
),
class = c("data.table", "data.frame")
)
> x
type value
1: current 10
2: prior 20
x
类型值
1:当前10
2:20岁以前
data.table上的“index”属性是什么?我如何防止将来创建它?我知道我的同事并非有意创建此索引,而是在联接或子集操作过程中,此data.table以某种方式获得了这种神奇的特性。index
是data.table使用的一种内部结构,旨在加速重复的索引操作。在1.9.4中,它曾经是一个bug,但是大多数bug都在1.9.5中被消除了。也可以通过选项(datatable.auto.index=FALSE)
禁用它。投票结束问题。这已在数据中修复。表
v>=1.9.5。投票也要结束。是的,但是对于标题中带有“魔力”的问题,+1…@BenBolker我也尝试添加[magic]标签。
> w[get('type')=='current',]
type value
1: current 10
x <- structure(
list(
type = c("current", "prior"),
value = c(10, 20)
),
class = c("data.table", "data.frame")
)
> x
type value
1: current 10
2: prior 20