How to replace a series of blanks by just one in a string in R?

3

How do I replace a series of blanks with just one, in R?

For example, suppose we have a string:

x <- "      non    non    non    non"

I want to make the content of x be "non non non non".

    
asked by anonymous 08.01.2015 / 18:46

1 answer

4

Two possible solutions:

gsub("\s+", " ", x)

and

gsub("[[:space:]]+", " ", x)
    
08.01.2015 / 19:42