for example i want to replace the character "A" for "Apple" and the character "B" for "Bannana"
junk <- data.frame(x = rep(LETTERS[1:4], 3),
y = letters[1:12],
stringsAsFactors = FALSE)
this provides:
x y
1 A a
2 B b
3 C c
4 D d
5 A e
6 B f
7 C g
8 D h
9 A i
10 B j
11 C k
12 D l
I tried to use
library(dplyr)
library(stringr)
mutate_if(junk,
is.character,
str_replace_all, pattern = "A", replacement = "Apple")
However i when i tried to do the same with "B" it removes the previous replacement for "A". And i want to keep both results.
mutate_if(junk,
is.character,
str_replace_all, pattern = "A", replacement = "Apple")
I want to keep both results "Apple" and "Bannana"