[R] getting last 2 charcters of a string, other "text" functions?

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Mon Oct 31 16:49:44 CET 2005



t c wrote:
> I wish to obtain the right-most n characters of a character string?  What is the appropriate function?
> 

See ?nchar ?substr

k <- 2
x <- "abcdef"
nc <- nchar(x)
substr(x, nc - k + 1, nc)

HTH,

--sundar




More information about the R-help mailing list