I have two tibbles x
and y
that I wish to combine into out
such that NA columns in x
are replaced by matching columns in y
library(tidyverse)
x <- tibble(name = c("hans", "dieter", "bohlen", "alf"),
location = c('NA','NA',1,2),
val1 = 1:4)
y <- tibble(name = c("hans", "dieter"),
location = c(2,2),
val1 = 1:2)
x
y
My desired output:
out <- tibble(name = c("hans", "dieter", "bohlen", "alf"),
location = c(2,2,1,2),
val1 = 1:4)
out
But using left_join
or similar functions doesn't overwrite the NA values in X. I can't work out a solution from this question Overwrite left_join dplyr to update data
p.s. I can't seem to get the variables to print - any help on how to format the code to do that? Many thanks!