[R] Trim function ?
Ernesto Jardim
ernesto at ipimar.pt
Thu May 9 19:26:05 CEST 2002
Hi
I did it in linux using:
cat file.blanks | tr -d '[:blank:]' | cat > file.noblanks
The rational is the same.
Thanks.
EJ
On Thu, 2002-05-09 at 17:05, ripley at stats.ox.ac.uk wrote:
> On 9 May 2002, Ernesto Jardim wrote:
>
> > 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 ?
>
> sub() can do this (and far, far more). Do you want to trim leading or
> trailing spaces or all spaces or what. For trailing spaces
> sub(" +$", "", x)
>
> will do what you want. For spaces both ends and no embedded spaces
> sub(" *([^ ]+) *", "\\1", x)
>
> and so on.
>
> --
> 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