Is there a simple way to substract strings across columns in a tibble or data.frame?
For example in the tibble below, is there a way to easily create column b from columns a and c? Similar to how I create c from a and b? (ie c = a + b, so b = c - a).
ex1 <- tibble(a = rep(c("orange", "green", "grey"), 2),
b = rep(c("ball", "hockey puck"), each = 3),
c = str_c(a, " ", b))
I would want the solution to work for any number of words in each string in columns a and b.
For example I was thinking something along the lines of the below code (breaking into words and doing a pair-wise comparison) but it doesn't quite work.
ex1 %>%
separate_rows(c) %>%
filter(b != c) %>%
group_by(a, b) %>%
summarize(a2 = str_c(c, collapse = " "))
Any ideas?