2

I have two data frames as seen below:

DF1:

ID  ITEM1   ITEM2
1001    1   1
1002    1   1
1003        1
1004    1   
1005    1   1

DF2:

ID  ITEM3
1001    1
1002    1

How do I merge both data frames to get the result:

ID  ITEM1   ITEM2   ITEM3
1001    1   1         1
1002    1   1         1
1003        1         
1004    1       
1005    1   1   
yopken
  • 21
  • 4

1 Answers1

5

You have several ways to perform a full join. Non matching keys will have NAs

Base R

merge(df1, df2, all=TRUE)

This is also valid for a data.table object

dplyr

library(dplyr)
df1 %>% full_join(df2)
linog
  • 5,786
  • 3
  • 14
  • 28