Don’t use the same for the data.frame and variables in it.
library(data.table)
a <- data.table(a = c(1,2,3,1,2,3), b = c("a", "b", "a", "b","a", "b"))
b <- a[b == "b"]
data.table
cannot distinguish which b
is. b
represents data.table b
and the variable b
in data.table a
.
a[a %in% b$a]
Error in b$a : $ operator is invalid for atomic vectors