library(tidyr, warn.conflicts = FALSE)
df <- expand_grid(x = c("a", NA), y = c("b", NA))
unite(df, "z", x:y, remove = FALSE)
# To remove missing values:
unite(df, "z", x:y, na.rm = TRUE, remove = FALSE)
# Separate is almost the complement of unite
unite(df, "xy", x:y) %>%
separate(xy, c("x", "y"))
# (but note `x` and `y` contain now "NA" not NA)
Run the code above in your browser using DataLab