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
  • 4,861
  • 9
  • 38
  • 56

2 Answers2

3

Use gsub():

gsub(" ", "", c)
gsub("[[:space:]]", "", c)
A5C1D2H2I1M1N2O1R2T1
  • 184,536
  • 28
  • 389
  • 466
1
library(stringr)
str_replace_all(c, " ", "")
Maiasaura
  • 30,900
  • 25
  • 101
  • 103