3
How do I replace a series of blank spaces 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: "non non non non non non non non".
3
How do I replace a series of blank spaces 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: "non non non non non non non non".
4
Two possible solutions:
gsub("\\s+", " ", x)
and
gsub("[[:space:]]+", " ", x)
Spoke a + in the second solution gsub("[[:space:]]+", " ", x)
Browser other questions tagged r regex
You are not signed in. Login or sign up in order to post.
I have no R skills, but the regular expression for finding the spaces would be
\s*
, then just replace by a space.– Oeslei
Thank you, I found the solution!
– Guilherme Duarte