[R] Substring and extract a certain number of characters

arun smartpink111 at yahoo.com
Thu Nov 14 16:50:21 CET 2013

s1 <- "hello.world"
s2 <- c("GLEm0045", "GLEn0042", "GLEz0048")


n <- 5
substr(s2,nchar(s2)-n +1,nchar(s2))


If I have a column that has "hello.world"  how   could I extract hello? 
 In addition in a column how can I extract the last 5 characters?    For example from character  G1Em0017  I wish to extract m0017 .

More information about the R-help mailing list