I am trying to find and replace some of the values of a data frame consisting of strings. The simple case like the following works,
library(stringr)
test1 <- c("one", "two", "three")
str_replace_all(string = test1,
                pattern = c('one' = "1ne",
                            'three' = "3ree"))
> [1] "1ne"  "two"  "3ree"
However, a more complicated case like the following isn't working. What am I doing wrong here?
test2 <- c("one (1) x1", "two (2) x2", "three (3) x3")
test2 <- c("one (1) x1", "two (2) x2", "three (3) x3")
str_replace_all(string = test2,
                   pattern = c('one (1) x1' = "X1",
                               'two (2) x2' = "X2"))
> [1] "one (1) x1"   "two (2) x2"   "three (3) x3"
 
     
    