I would like to merge two data frames where one has more variables (columns) whereas the other has more observations (rows). A simplified example of how they are set up are below:
Dataframe 1:
ID Date Indicator
12345 01/01/2008 1
54321 12/01/2008 1
Dataframe 2:
ID Date
12345 01/01/2008
12345 01/31/2008
12345 02/28/2009
24681 01/01/2008
54321 12/01/2008
54321 12/20/2008
What I would like to do is only keep the rows in which the ID's are an exact match. For example, I would like the following output:
New dataframe:
ID Date Indicator
12345 01/01/2008 1
12345 01/31/2008 NA
12345 02/28/2009 NA
54321 12/01/2008 1
54321 12/20/2008 NA
I have tried
new <- merge(df1, df2, all=TRUE)
but this results in the merging of ALL rows, whereas I only want the rows from df2 with ID that are seen in df1.
Any help is appreciated!