library(tidyverse)
reprex for you to reproduce:
library(tidyverse)
tibble(
x1 = c(1, 2, NA, NA, 5),
y1 = c(4, 3, NA, NA, 7),
x2 = c(NA, NA, 6, 7, NA),
y2 = c(NA, NA, 2, 4, NA),
replace1 = c("A", "B", "C", "D", "E"),
replace2 = c("F", "G", "H", "I", "J")
)
I have this dataframe:
# A tibble: 5 x 6
x1 y1 x2 y2 replace1 replace2
<dbl> <dbl> <dbl> <dbl> <chr> <chr>
1 1 4 NA NA A F
2 2 3 NA NA B G
3 NA NA 6 2 C H
4 NA NA 7 4 D I
5 5 7 NA NA E J
I need the dataframe to be like this, which tidyverse pipeline will get me that?.
# A tibble: 5 x 6
x1 y1 x2 y2 replace1 replace2
<chr> <chr> <chr> <chr> <chr> <chr>
1 1 4 A F A F
2 2 3 B G B G
3 C H 6 2 C H
4 D I 7 4 D I
5 5 7 E J E J