I want to create a df that combines elements from 2 columns in other dfs.
Below is df1:
id visit v1
1 4 25
1 5 23
2 1 8
Below is df2:
id visit v2
1 3 11
1 4 5
2 1 9
I want:
id visit v1 v2
1 3 NA 11
1 4 25 5
1 5 23 NA
2 1 8 9
I tried this
df3 <- bind_rows(df1, df2) %>%
group_by(id, visit) %>%
distinct() %>%
arrange(id, visit)
But it's not doing an exact merge on id and visit. See snipbit below where participant 1 and visit 4 is not merging.
id visit v1 v2
1 3 NA 11
1 4 25 NA
1 4 NA 5
Can someone please help?