[R] Function to eliminate blank space within strings?

jim holtman jholtman at gmail.com
Fri Jul 3 12:55:29 CEST 2009


How much blank space do you want to remove?  all to one, all to none,
leading, trailing?

You can use regular expressions:

> x <- "   my    test     string      "
> # leading
> sub("^ +", "", x)
[1] "my    test     string      "
> # trailing
> sub(" +$", '', x)
[1] "   my    test     string"
> # multiple to one
> gsub(" +", " ", x)
[1] " my test string "
>


On Fri, Jul 3, 2009 at 4:34 AM, Agustin Lobo<aloboaleu at gmail.com> wrote:
> Is there an specific function
> to eliminate blank space within
> strings?
> Thanks
> --
> Dr. Agustin Lobo
> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
> LLuis Sole Sabaris s/n
> 08028 Barcelona
> Spain
> Tel. 34 934095410
> Fax. 34 934110012
> email: Agustin.Lobo at ija.csic.es
> http://www.ija.csic.es/gt/obster
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list