To insert a character at a specific index in a string in R, you can use the `substr()` function.
In this example,
str
with a value of "Hello World"
.substr()
function to insert the character '!'
at index 6
.str
.str <- "Hello World"
str <- paste0(substr(str, 1, 5), "!", substr(str, 6, nchar(str)))
print(str)
Hello! World
In this tutorial, we learned How to Insert Character at Specific Index in String in R language with well detailed examples.