str_replace_all replacing named vector elements iteratively not all at once

后端 未结 4 2000
误落风尘
误落风尘 2021-01-18 09:15

Let\'s say I have a long character string: pneumonoultramicroscopicsilicovolcanoconiosis. I\'d like to use stringr::str_replace_all to replace certain letters w

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 09:34

    There is probably an order in what the function does, so after replacing all c by s, you replace all s by c, only c remains .. try this :

    long_string %>% str_replace_all(c(c ="X", s = "U"))  %>% str_replace_all(c(X ="s", U = "c"))
    

提交回复
热议问题