purrr:map2:
df %>%
mutate_if(is.factor, as.character) %>%
mutate(col3 = map2(strsplit(y2, "\\."), strsplit(y1, "\\."), setdiff))
: factor character, setdiff "." -split y2 y1. , col3 list.
Update
, unnest character list. , col3 list character, :
df %>%
mutate_if(is.factor, as.character) %>%
mutate(col3 = map2(strsplit(y2, "\\."), strsplit(y1, "\\."), setdiff)) %>%
rowwise() %>%
mutate(col3 = paste(col3, collapse = "."))
- col3 ( ); rowwise() - paste.
:
y1 <- c("a.b.","a.","b.c.d.")
y2 <- c("a.b.c.e.","a.b.","b.c.d.")
df <- data.frame(y1,y2)
df %>%
mutate_if(is.factor, as.character) %>%
mutate(col3 = map2(strsplit(y2, "\\."), strsplit(y1, "\\."), setdiff)) %>%
rowwise() %>%
mutate(col3 = paste(col3, collapse = "."))