Is there a way to dynamically merge columns with NA values?
tibble(
x = c(1:2, NA, NA, NA, NA, NA),
y = c(NA, NA, 4:7, NA),
z = c(NA, NA, NA, NA, NA, NA, 9)
)
# A tibble: 7 x 3
x y z
<int> <int> <dbl>
1 1 NA NA
2 2 NA NA
3 NA 4 NA
4 NA 5 NA
5 NA 6 NA
6 NA 7 NA
7 NA NA 9
expect:
# A tibble: 7 x 3
x y z
<int> <int> <dbl>
1 1 NA NA
2 2 NA NA
3 4 4 NA
4 5 5 NA
5 6 6 NA
6 7 7 NA
7 9 NA 9
This example is a read from an xlsx file, so in some cases the column yor z may not exist