This would be equivalent to dplyr::full_join.
library(dplyr)
have1 <- data.frame(
'id' = c(10, 20, 30),
'a' = c(1, 3, 5),
'b' = c(2, 4, 6)
)
have2 <- data.frame(
'id' = c(10, 30, 40),
'c' = c(0, 1, 1)
)
have <- full_join(
have1,
have2,
by = 'id'
)
have
#> id a b c
#> 1 10 1 2 0
#> 2 20 3 4 NA
#> 3 30 5 6 1
#> 4 40 NA NA 1
Created on 2022-05-13 by the reprex package (v1.0.0)
Or, if you are feeling more SAS like, you can use merge from base R:
have <- merge(
have1,
have2,
by = 'id',
all = TRUE
)
have
#> id a b c
#> 1 10 1 2 0
#> 2 20 3 4 NA
#> 3 30 5 6 1
#> 4 40 NA NA 1
Created on 2022-05-13 by the reprex package (v1.0.0)