To replace a substring in a string in R, you can use the `sub()` function or regular expressions.
In this example,
str
with a value of "Hello World"
.sub()
function to replace the substring "World"
with "Universe"
.str
.str <- "Hello World"
str <- sub("World", "Universe", str)
cat(str, '\n')
Hello Universe
In this tutorial, we learned How to Replace a Substring in String in R language with well detailed examples.