I want to remove white-spaces from a character string when the number of continuous white-spaces between 2 non-whitespace chars words is less than a certain number.
For example,
a <- c("I want only <5 white-spaces removed")
I know I can remove all the spaces using gsub(' ', '', a). However, I want to remove white-spaces between two non-whitespace chars words only when the total white-space is less than 5. So I want the following
a_adj <- c("Iwant only <5 white-spacesremoved")
I tried this gsub('{,5} ', '', a). But it still removes all white-spaces. Can someone help, please?
Thanks