[R] getting last 2 charcters of a string, other "text" functions?

Tobias Verbeke tobias.verbeke at telenet.be
Mon Oct 31 17:01:56 CET 2005


t c wrote:

>I wish to obtain the right-most n characters of a character string?  What is the appropriate function?
>  
>
You could make one yourself:

rightmostn <- function(x, n){
  res <- substr(x, nchar(x)-n+1, nchar(x))
  return(res)
}
magic <- "hocuspocus"
rightmostn(magic, 5)
[1] "pocus"

HTH,
Tobias

>
>		
>---------------------------------
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>  
>




More information about the R-help mailing list