Issue
Here are 2 data frames:
df1 <- data.frame(ID=c(1,2,3,4))
df1
df2 <- data.frame(ID=c(1,3))
df2
How can I join them to get the following output?:
# ID.1 ID.2
# 1 1
# 2
# 3 3
# 4
Thanks!
Solution
Try dplyr::left_join
with keep = TRUE
:
> left_join(df1, df2, keep = TRUE, suffix = c('.1', '.2'), by = 'ID')
ID.1 ID.2
1 1 1
2 2 NA
3 3 3
4 4 NA
Answered By - Dmitry Zotikov Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.