Using the stringr package, you can easily replace regular expressions in vector form.
Question: How can I do the following:
Replace every word in
hello,world??your,make|[]world,hello,pos
to various substitutions, for example. increase in number
1,2??3,4|[]5,6,7
Please note that simple delimiters cannot be accepted; a practical use case is more complex.
stringr::str_replace_all doesn't seem to work because it
str_replace_all(x, "(\\w+)", 1:7)
creates a vector for each substitution, applied to all words, or has indefinite and / or repeating input records so that
str_replace_all(x, c("hello" = "1", "world" = "2", ...))
will not work for this purpose.
source share