0

Possible Duplicate:
How to remove all whitespace from a string in R?

I have a string like

c<-"abc def gh"

I need to remove every space from this string and get sth lik

c<-"abcdefgh"

How do that in r?

Community
  • 1
  • 1
user785099
  • 5,323
  • 10
  • 44
  • 62

2 Answers2

3

Use gsub():

gsub(" ", "", c)
gsub("[[:space:]]", "", c)
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
1
library(stringr)
str_replace_all(c, " ", "")
Maiasaura
  • 32,226
  • 27
  • 104
  • 108