Re: [R] Substring and extract a certain number of characters

2013-11-14 Thread arun
Also, library(stringr) str_sub(s2,-5,-1) str_extract(s1,"[[:alpha:]]+") A.K. On Thursday, November 14, 2013 10:50 AM, arun wrote: Try: s1 <- "hello.world" s2 <- c("GLEm0045", "GLEn0042", "GLEz0048")  substr(s1,1,5) #or gsub("\\..*","",s1) n <- 5 substr(s2,nchar(s2)-n +1,nchar(s2)) A.K.

Re: [R] Substring and extract a certain number of characters

2013-11-14 Thread arun
Try: s1 <- "hello.world" s2 <- c("GLEm0045", "GLEn0042", "GLEz0048")  substr(s1,1,5) #or gsub("\\..*","",s1) n <- 5 substr(s2,nchar(s2)-n +1,nchar(s2)) A.K. 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 characte