0

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?

  • 1
    Have a look at https://stackoverflow.com/questions/28702960/find-complement-of-a-data-frame-anti-join – kath Oct 29 '19 at 15:37
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Oct 29 '19 at 15:40

0 Answers0