We can use unite
with na.rm
library(dplyr)
library(tidyr)
df %>%
unite(included, starts_with('include'), na.rm = TRUE, sep = "| ") %>%
select(ignore, included)
-output
# A tibble: 3 x 2
# ignore included
# <chr> <chr>
#1 j a| d| f| i
#2 k b| e| g
#3 l c| h
CLICK HERE to find out more related problems solutions.