[R] Odp: Remove space from string

Bos, Roger roger.bos at rothschild.com
Fri Jan 13 17:27:19 CET 2012


I have NO knowledge of regexpr, but someone helped me out once and I put
it into a function I call "trim".  Here is the line I use:

function(x) gsub("^[[:space:]]+|[[:space:]]+$", "", x)

One more thing you can try.  Hope it helps, Roger

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Petr PIKAL
Sent: Friday, January 13, 2012 7:40 AM
To: Vikram Bahure
Cc: r-help at r-project.org
Subject: [R] Odp: Remove space from string

Hi

> 
> Dear R users,
> 
> I have some trivial query.
> 
> I have a string, I want to remove space from the string.
> 
> For eg.
> 
> Input:
> a <- " Remove space "
> 
> Output required:
> "Removespace"

It seems to be simple. Even myself with very poor knowledge of regexpr
can suggest solution.

gsub(" ", "", a)

Regards
Petr


> 
> I tried using str_trim but only removes end spaces. library(stringr).
> 
> Regards
> Vikram
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

______________________________________________
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.
***************************************************************

This message is for the named person's use only. It may\...{{dropped:14}}



More information about the R-help mailing list