I would like to replace one pattern given by a list by the other pattern given by another list.
I do it like this:
strings$old <- c("apple banana orange", "peach apple orange", "apple orange pear", "orange apple banana", "apple orange peach")
words to replace <- c("banana", "peach", "pear")
replacements <- c("b", "p", "pe")
what I do:
current <- paste(c(replace), collapse='|')
change_to <- paste(c(replacements ), collapse='|')
strings$new <-str_replace_all(strings$old, current, change_to)
However, I get an error. What I would like to see is:
c("apple b orange", "p apple orange", "apple orange pe", "orange apple b", "apple orange p")