0

If I have 2 data with some same column names, and I want to check the different obsercations, how can I do?

Here is my sample data:

# dt1
ID  Name  ColA   ColB
2   Peter 1      2
4   Freda 50     4
5   Jean  8      10

# dt2
ID  Name  ColA   ColB  ColC   ColD
1   Roger 1      2     400
2   Peter 1      2     500    2000
3   Tina  3      50           20
4   Freda 50     4     500    300
5   Jean  8      10    89     54

ColA, ColB, ColC, and ColD are unimportant. I just want to check ID and Name.

Second, check dt2 which rows are not the same as dt1.
Therefore, the result is:

ID  Name  ColA   ColB  ColC   ColD
1   Roger 1      2     400
3   Tina  3      50           20

Because my real data is extremely large, how can I check?

Peter Chen
  • 1,464
  • 3
  • 21
  • 48
  • 2
    You just want an anti-join by ID and Name? If so, see [this](https://stackoverflow.com/questions/28702960/find-complement-of-a-data-frame-anti-join) – David Arenburg Aug 02 '17 at 07:30

1 Answers1

2
> library(dplyr) 
> anti_join(dt2,dt1,by=c('ID','Name'))
Prasanna Nandakumar
  • 4,295
  • 34
  • 63