Remove extra white space from between letters in R using gsub()

前端 未结 1 1445
-上瘾入骨i
-上瘾入骨i 2021-01-13 18:41

There are a slew of answers out there on how to remove extra whitespace from between words, which is super simple. However, I\'m finding that removing extra whitespace

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-13 18:52

    You may try this,

    > x <- c("L L C", "P O BOX 123456", "NEW YORK")
    > gsub("(?<=\\b\\w)\\s(?=\\w\\b)", "", x,perl=T)
    [1] "LLC"           "PO BOX 123456" "NEW YORK" 
    

    It just removes the space which exists between two single word characters.

    0 讨论(0)
提交回复
热议问题