我在尝试根据单独的列值对行进行子集化后返回数据表的列时遇到data.table_1.11.4中的错误。例如,
library(data.table)
set.seed(123)
dt <- data.table(
x = 1:10,
y = LETTERS[1:10],
z = sample(c(T, F), 10, replace = T)
)
> dt
x y z
1: 1 A TRUE
2: 2 B FALSE
3: 3 C TRUE
4: 4 D FALSE
5: 5 E FALSE
6: 6 F TRUE
7: 7 G FALSE
8: 8 H FALSE
9: 9 I FALSE
10: 10 J TRUE
当我尝试基于逻辑值进行子集时,我收到此错误
> dt[z == TRUE, x]
Error in setDT(list(indices = rep.int(indices__, len__), irows = irows)) :
object 'CexpandAltRep' not found
根据我以前的经验,以及我在小插曲中看到的内容,情况并非如此。仅在基于逻辑值进行子集化时才会出现这种情况。在对字符值进行子集化时,我也会得到奇怪的值&#34; TRUE&#34;。以下是一些正常工作或返回奇怪值的其他实例
> # Expected
> dt[y == E, x]
Error in eval(stub[[3L]], x, enclos) : object 'E' not found
>
> # Expected
> dt[y == "E", x]
[1] 5
>
> # Unexpected
> dt[z == "TRUE", x]
[1] 1 3 6 10
>
> # Unexpected
> class(dt[z == "TRUE", x])
[1] "integer"
有关可能发生的事情的任何想法?
编辑:
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.11.4
loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1
答案 0 :(得分:0)
感谢大家的帮助。我认为评论中的讨论非常好,所以我不想删除这个问题。通过更新到最新版本的R解决了该问题。