- sub
Substitute first occurence using sub
examples/strings/replace_substring.R
text <- "One cat two cats and another single cat" print(text) print(sub('cat', 'dog', text)) print(text)
[1] "One cat two cats and another single cat" [1] "One dog two cats and another single cat" [1] "One cat two cats and another single cat"