Alex Rivera | Logout

Extracting the last n characters from a string in R

Asked 2011-11-01T08:11:19.490
386

How can I get the last n characters from a string in R? Is there a function like SQL's RIGHT?

Edit
Report

1 Answer

24
str = 'This is an example'
n = 7
result = substr(str,(nchar(str)+1)-n,nchar(str))
print(result)

> [1] "example"
> 
answered 2011-11-01T08:36:02.027

Your Answer