Given the following code:
library(data.table)
df1<-data.table(a=c(1,1,2,2,1),b=c(1,3,1,1,2),c=c(2,9,8,3,7))
df2<-data.table(a=c(1,2),b=c(1,1))
n<-c("a","b")
I want to select all rows of df1 which have identical rows in df2, considering only the columns given by n.
So, the result should be:
a b c
1: 1 1 2
2: 2 1 8
3: 2 1 3
How can I do this efficiently? Thanks!