The operator %in%is a wrapper for the matching function that returns a "vector of the same length as x". For instance:
> match(c("a", "b", "c"), c("a", "a"), nomatch = 0) > 0
#
When used in idata tables, however
(dt1 <- data.table(v1 = c("a", "b", "c"), v2 = "dt1"))
v1 v2
1: a dt1
2: b dt1
3: c dt1
(dt2 <- data.table(v1 = c("a", "a"), v2 = "dt2"))
v1 v2
1: a dt2
2: a dt2
dt1[v1 %in% dt2$v1]
v1 v2
1: a dt1
2: a dt1
Copies Received. If the expected behavior %in%inside the i.table data does not produce the same result as
dt1[dt1$v1 %in% dt2$v1]
v1 v2
1: a dt1
i.e. no duplicates?
source
share