Here are several ways to find the last character in a string:
> x <- "abc"
> substring(x, nchar(x))
[1] "c"
> sub(".*(.)", "\\1", x)
[1] "c"
> library(gsubfn)
> strapply(x, ".$")[[1]]
[1] "c"
On Mon, Oct 19, 2009 at 3:52 PM, Jason Rupert wrote:
> I am currently being defeated by grep. I am a
Well, regexpr() can do it; the magical incantation is
regexpr(".$",yourstring)
See ?regexpr for details.
However, as your task really doesn't involve MATCHING characters, but
COUNTING characters, it might be simpler to use nchar() and substr():
n <- nchar(yourstring)
lastLetter <- substr(your
2 matches
Mail list logo