Skip to content
Prev 333158 / 398506 Next

Substring and extract a certain number of characters

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 characters? ? ?For example from character ?G1Em0017 ?I wish to extract m0017 .