I'm trying to match df1 to df2 on variables 1 and 2 in order to remove the matches from df1. I'm able to match against a single column, but not against a combination of columns.
> match(df1[,1], df2[,1]) #this returns the indices I need, but only for one variable
[1] NA 2 NA NA NA 42 19 NA NA NA NA
> match(df1[,1:2], df2[,c(1,2)]) #this only gives two results (I'm guessing for the two columns
[1] NA NA
I realize merge
would work if I want to do an inner join to find only the common records using by=c(1,2)
, but would this preserve the indices I would need to then go back to the original df1 and remove the matched records?