2

I would like to reduce all spaces longer than a single space in a string to a single space.

foo(" 1   2    3     4                 5 ")
[1] " 1 2 3 4 5 "
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Francis Smart
  • 3,875
  • 6
  • 32
  • 58
  • 1
    possible duplicate of [How to remove extra white space between words inside a character vector using R?](http://stackoverflow.com/questions/19128327/how-to-remove-extra-white-space-between-words-inside-a-character-vector-using-r) – hrbrmstr Apr 12 '14 at 01:40
  • Good point. I did not see that. – Francis Smart Apr 12 '14 at 06:32

1 Answers1

8

That would work:

gsub(' +',' ',foo) 

:)

(edited to take into account Zach's comment)

Jealie
  • 6,157
  • 2
  • 33
  • 36