[R] removing trailing spaces

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Feb 7 20:48:22 CET 2001


On Wed, 7 Feb 2001, Bernie McConnell wrote:

> I'm sure there must be a simple (and documented) way of doing this, but it has me stumpted. I want to remove trailing spaces from character vector yy:
>
>
> yy <<- c("abc  ","def ","hij   ")

(Not sure you really wanted <<- there.  It is rarely correct.)

sub(" +$", "", yy)

is as good as any, I believe.  That says replace one or more spaces before
the end of the string (denoted by $) by nothing.

BDR

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list