[R] trim a string

Mike R mike.rstat at gmail.com
Fri Jun 17 20:53:40 CEST 2005


> How to trim the leading and trailing white space off of a string?
> 
>  If the variable is "  E              " I need to convert it to "E".

gsub('^[[:space:]]+', '', "   E     ")
gsub('[[:space:]]+$', '', "   E     ")

as in R-2.1.0/library/base/html/grep.html




More information about the R-help mailing list