To remove the first N characters of a string in R, you can use the substr function starting from index N+1.
In this example,
str1
with a value of 'Hello World'
.str1 <- 'Hello World'
str1 <- substr(str1, 4, nchar(str1))
cat('Modified string is: ', str1)
Modified string is: lo World
In this example,
str2
with a value of 'apple'
.str2 <- 'apple'
str2 <- substr(str2, 3, nchar(str2))
cat('Modified string is: ', str2)
Modified string is: ple
In this tutorial, we learned How to Remove first N Characters in a String in R language with well detailed examples.