I have such a data frame(df) with ID's
ID
1
2
3
4
5
6
I have such data frames df1 and df2:
df1:
ID x
3 656
5 678
df2:
ID x
1 45
2 954
6 1245
I want to merge df1 and df2 onto df. The resulting data frame will be:
ID x
1 45
2 954
3 656
4 NA
5 678
6 1245
In my real problem, I have a lot of data frames to merge with df(df also have a lot of more ID's). I want to this merging procedure in a loop. How can I do that in R? I will bevery glad for any help. Thanks a lot.
xbesides theid, it looks like you don't actually need to merge, just to bind the rows together (unless you want to keep observations with no value inxasNA). Look atrbind_all.dplyrlibrary you can do justdf %>% left_join(df1) %>% left_join(df2)or maybebind_rows(df1, df2)if you dont need rows wherexisNA