I have the following data.table
s
library(data.table)
dt_1 <- data.table(id = c('cg','fs','fs'),
v1 = c('a','a','b'),
v2 = c('d','e','f'))
dt_2 <- data.table(id = c('cg','fs','cg'),
v1 = c('a','a','b'))
And I would like to filter dt_1
based on dt_2
. In the end I would like to end up with
id v1 v2
1: fs b f
So filter out the exact rows of dt_1
that are contained in dt_2
This operation
dt_1[!(id%in%dt_2$id & v1%in%dt_2$v1)]
Does not work because it takes also the inner combinations of dt_2$id
and dt_2$v1
and this
dt_1[!dt_2]
throws an error.
Any ideas ?