To extract last n characters from a string, you can use the str_sub function from the stringi package as follows:
stri_sub(x,i,n)
Where
x - String/Vector
i - Start index
n - Final index
For example:
library("stringi")
vec <- c("Hello World")
str <- stri_sub(vec,-5,-1)
str
Output:
[1] "World"
If you want to explore more in R programming then watch this R programming tutorial for beginner: