[R] getting last 2 charcters of a string, other "text" functions?
Earl F. Glynn
efg at stowers-institute.org
Mon Oct 31 16:59:10 CET 2005
"t c" <quantpm at yahoo.com> wrote in message
news:20051031153755.80990.qmail at web35006.mail.mud.yahoo.com...
> I wish to obtain the right-most n characters of a character string? What
is the appropriate function?
substr will work:
> x <- c("abcd", "xyz")
> N <- 2
> substr(x, nchar(x)-N+1, nchar(x))
[1] "cd" "yz"
> N <- 3
> substr(x, nchar(x)-N+1, nchar(x))
[1] "bcd" "xyz"
efg
More information about the R-help
mailing list