I'm trying to retain all columns in x, even tho they are missing in y.
This works when I join with y having only a single "group", adding NA entries as expected.
However when I add another "group" to y values are silently dropped.
What am I missing?
Thanks!
library(magrittr)
base <- data.frame(
"key" = c(1,2,3,4),
"v_a" = c("asdf","fdsa","qwert","trewq")
)
join1 <- data.frame(
"key" = c(1,2,3),
"group" = c("g_a","g_a","g_a"),
"value" = c(111,222,333)
)
join2 <- data.frame(
"key" = c(1,2,3,4),
"group" = c("g_b","g_b","g_b","g_b"),
"value" = c(444,555,666,777)
)
joincombined <- dplyr::bind_rows(join1, join2)
# joining a single group retains all keys in base
# NAs are correctly assigned for missing values in "group" and "value"
res_singleJoin <- base %>%
dplyr::full_join(join1, by = "key")
# joining the combined df drops missing entries "group" and "value"
res_combinedJoin <- base %>%
dplyr::full_join(joincombined, by = "key")