paste together strings that come from names that fit a pattern and ignore nas

We can use unite with na.rm

df %>%
    unite(included, starts_with('include'), na.rm = TRUE, sep = "| ") %>%
   select(ignore, included)


# 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.

Leave a Comment

Your email address will not be published.

Scroll to Top