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
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.0
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
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
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-wh
5 matches
Mail list logo