How to filter cases in a data.table by multiple conditions defined in another data.table
setkey(dt1, A)
dt1[dt_filter, allow = T][B != i.B, !'i.B']
# A B C
#1: 1 1 1
#2: 1 1 2
#3: 1 3 1
#4: 1 9 2
#5: 2 1 1
#6: 2 1 2
#7: 2 4 1
#8: 2 5 2
Two other solutions which read more clearly and which don't need to setkey
:
dt1[ which(dt1$A == dt_filter$A & dt1$B != dt_filter$B) ,]
Now using %in%
dt1[dt1$A %in% dt_filter$A & !(dt1$B %in% dt_filter$B) ,]