请参见以下示例:
library(data.table)
DT <- data.table(x = 1:3, y = list(character(), "bar", "baz"))
DT[]
#> x y
#> 1: 1
#> 2: 2 bar
#> 3: 3 baz
!lengths(DT$y)
#> [1] TRUE FALSE FALSE
# this is wrong:
DT[!lengths(y), ]
#> x y
#> 1: 2 bar
#> 2: 3 baz
# but this is right (adding brackets):
DT[(!lengths(y)), ]
#> x y
#> 1: 1
DT2 <- copy(DT)
# this is wrong
DT[!lengths(y), y:= list(list("foo"))][]
#> x y
#> 1: 1
#> 2: 2 foo
#> 3: 3 foo
# but this is right (adding brackets):
DT2[(!lengths(y)), y:= list(list("foo"))][]
#> x y
#> 1: 1 foo
#> 2: 2 bar
#> 3: 3 baz
由reprex package(v0.3.0)于2019-07-11创建
这是错误还是!
在 data.table 中的i
中起特殊作用?