I\'m trying to quickly replace multiple characters in a string with another character such as *
*
For example, I have a string such as:
string
We can use substring
substring
v1 <- c(1, 4, 6, 9) for(i in seq_along(v1)) substring(string, v1[i], v1[i]) <- "*" #[1] "*bc*e*gh*j"
As we are using stringi, another option is
stringi
library(stringi) stri_sub_all(string, from = v1, length = 1) <- "*" string #[1] "*bc*e*gh*j"