我想data.table(1.9.6)包的unique-function中有一个错误:
小例子:
test <- data.table(a = c("1", "1", "2", "2", "3", "4", "4", "4"),
b = letters[1:8],
d = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE))
a b d
1: 1 a TRUE
2: 1 b TRUE
3: 2 c FALSE
4: 2 d FALSE
5: 3 e TRUE
6: 4 f FALSE
7: 4 g FALSE
8: 4 h FALSE
test[d == TRUE, `:=` (b = "M")]
test <- unique(test, by = c("a", "b"))
a b d
1: 1 M TRUE
2: 2 c FALSE
3: 2 d FALSE
4: 3 M TRUE
5: 4 f FALSE
6: 4 g FALSE
7: 4 h FALSE
Run Code Online (Sandbox Code Playgroud)
在这一点上,一切都很完美,但现在我只想选择列d为真的行:
test[d == TRUE]
a b d
1: 1 M TRUE
Run Code Online (Sandbox Code Playgroud)
但结果是错误的.
该错误刚刚在开发存储库中修复.
library(data.table)
test <- data.table(a = c("1", "1", "2", "2", "3", "4", "4", "4"),
b = letters[1:8],
d = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE))
test[d == TRUE, `:=` (b = "M")]
test <- unique(test, by = c("a", "b"))
test[d == TRUE]
# a b d
#1: 1 M TRUE
#2: 3 M TRUE
Run Code Online (Sandbox Code Playgroud)
开发版data.table已经在drat repo中发布,可以通过以下方式轻松安装:
install.packages("data.table", repos="https://Rdatatable.github.io/data.table", type="source")
Run Code Online (Sandbox Code Playgroud)
谢谢报道!