Quantcast

How to remove white spaces

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to remove white spaces

Bos, Roger
All,

I am storing a string of email addresses in a table and when I retrieve
them using a RODBC statement such as:

test = sqlQuery(xf, "select specialist from
roger_sector_specialist")$specialist

'test' is of mode list and includes a bunch of white space.  As a
work-around I convert 'test' to a character string, split it based on a
white space, then take the first element:

test = strsplit(as.character(test), " ")
emaillist = test[[1]][1]
   
But I am sure there is a better way.  I did help.search("trim white
space") and R didn't return anything, which I found strange.  Any
advice?

Thanks,

Roger

********************************************************************** *
This message is for the named person's use only. It may
contain confidential, proprietary or legally privileged
information. No right to confidential or privileged treatment
of this message is waived or lost by any error in
transmission. If you have received this message in error,
please immediately notify the sender by e-mail,
delete the message and all copies from your system and destroy
any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message
if you are not the intended recipient.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to remove white spaces

Prof Brian Ripley
On Fri, 15 Aug 2008, Bos, Roger wrote:

> All,
>
> I am storing a string of email addresses in a table and when I retrieve
> them using a RODBC statement such as:
>
> test = sqlQuery(xf, "select specialist from
> roger_sector_specialist")$specialist
>
> 'test' is of mode list and includes a bunch of white space.

I don't see how: sqlQuery returns a data frame, and this is one column of
it.  You can have 'list' columns in data frames, but not from sqlQuery.

> As a work-around I convert 'test' to a character string, split it based
> on a white space, then take the first element:
>
> test = strsplit(as.character(test), " ")
> emaillist = test[[1]][1]
>
> But I am sure there is a better way.  I did help.search("trim white
> space") and R didn't return anything, which I found strange.  Any
> advice?

help.search() is not a full-text search.  RSIteSearch("trim white space")
give lots of relevant info (including the difference between " " and white
space).

See ?gsub for trimming trailing whitespace.

--
Brian D. Ripley,                  [hidden email]
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] 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.
Loading...