[R] Trim function ?
ripley at stats.ox.ac.uk
Thu May 9 18:09:51 CEST 2002
On 9 May 2002, Douglas Bates wrote:
> Ernesto Jardim <ernesto at ipimar.pt> writes:
> > Hi
> > I've imported some data from a oracle database and the strings have a
> > lot of blank space (because of the delimiter). I want to remove these
> > blanks space with something similar to a trim function.
> > I don't find a trim function or something similar. Can someone give a
> > help on this ?
> If you want to remove trailing blanks you can use sub with the regular
> expression ' +$'.
> > str = 'Now is the time '
> > sub(' +$', '', str, extended = TRUE)
>  "Now is the time"
> I had hoped you could use '\s+$' or '\\s+$' but that doesn't seem to
> work. I guess we would need the perl regular expression library, of
> which there has been some discussion, to do that.
In today's R-devel
> sub('\\s+$', '', str, perl = TRUE)
 "Now is the time"
but as it was literally added a few hours ago, don't expect it to have
bedded down yet. (I have support under Windows, but no connectivity to
commit it at present.)
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