Re: [R] Remove all whitespaces

2011-05-05 Thread Shekhar
A more elegant way would be:

myString<-"1 2 3 4 5"
myString<-paste(unlist(strsplit(myString," ")),collapse="")

The output will be "12345"

Regards,
Som Shekhar

__
R-help@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.


Re: [R] Remove all whitespaces

2011-05-05 Thread Janko Thyson
If your whitespace does not only contain regular spaces, this might also 
be useful:

x.1 <- "\t1 2 \n3   4"
write(x.1, "test.txt")
x.2 <- readLines("test.txt")
x.3 <- gsub("[[:space:]]", "", x.2)
x <- paste(x.3, collapse="")

See ?regex for details on regular expressions in R.

HTH,
Janko

On 05.05.2011 11:02, Ivan Calandra wrote:
> Hi Joel,
>
> Try this:
> x <- "1 2 3 4 5 6 7 8 9 "
> gsub(" ", "", x)
>
> Ivan
>
>
> Le 5/5/2011 10:50, Joel a écrit :
>> Hi
>>
>> I got a string that looks something like this
>>
>> 1 2 3 4 5 6 7 8 9 ...
>>
>> and I want it to be
>>
>> 123456789...
>>
>> So I want to remove all spaces (or whitespaces) from my string.
>>
>> Anyone know a good way of doing this?
>>
>> //Joel
>


-- 


*Janko Thyson*
janko.thy...@googlemail.com 

Jesuitenstraße 3
D-85049 Ingolstadt

Mobile: +49 (0)176 83294257

This e-mail and any attachment is for authorized use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by any other party.
If you are not an intended recipient then please promptly delete this
e-mail and any attachment and all copies and inform the sender.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Remove all whitespaces

2011-05-05 Thread Tom Osborn
sed?

1,$s/ //g
  - Original Message - 
  From: Joel
  To: r-help@r-project.org
  Sent: Thursday, May 05, 2011 6:50 PM
  Subject: [R] Remove all whitespaces


  Hi

  I got a string that looks something like this

  1 2 3 4 5 6 7 8 9 ...

  and I want it to be

  123456789...

  So I want to remove all spaces (or whitespaces) from my string.

  Anyone know a good way of doing this?

  //Joel

  --
  View this message in context: 
http://r.789695.n4.nabble.com/Remove-all-whitespaces-tp3497867p3497867.html
  Sent from the R help mailing list archive at Nabble.com.

  __
  R-help@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. 

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Remove all whitespaces

2011-05-05 Thread Ivan Calandra

Hi Joel,

Try this:
x <- "1 2 3 4 5 6 7 8 9 "
gsub(" ", "", x)

Ivan


Le 5/5/2011 10:50, Joel a écrit :

Hi

I got a string that looks something like this

1 2 3 4 5 6 7 8 9 ...

and I want it to be

123456789...

So I want to remove all spaces (or whitespaces) from my string.

Anyone know a good way of doing this?

//Joel
  


--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
R-help@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] Remove all whitespaces

2011-05-05 Thread Joel
Hi

I got a string that looks something like this

1 2 3 4 5 6 7 8 9 ...

and I want it to be 

123456789...

So I want to remove all spaces (or whitespaces) from my string.

Anyone know a good way of doing this?

//Joel

--
View this message in context: 
http://r.789695.n4.nabble.com/Remove-all-whitespaces-tp3497867p3497867.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.