删除多个 space,但在 R 中保留单个 space

Remove multiple spaces but leave single space in R

我有如下文字。

"The comm   unity is here to help you wi   th specific co   ding"

我想删除句子中的三重 space,同时保留一个 space。

我试过了

gsub(text, "   ", "")

但是没用。

要恰好删除单词的三个空格,请使用:

x <- "The comm   unity is here to help you wi   th specific co   ding"
output <- gsub("\b[ ]{3}\b", "", x)
output

[1] "The community is here to help you with specific coding"

这行得通吗,删除多个 space:

st <- "The comm   unity is here to help you wi   th specific co   ding"
st
[1] "The comm   unity is here to help you wi   th specific co   ding"
gsub('\s{2,}','',st)
[1] "The community is here to help you with specific coding"