在R中拆分联合词

时间:2016-11-27 21:07:20

标签: r regex string pattern-matching character

我正在尝试拆分结构如下的字符串:

string <- c("ThisThat","OneTwo","LeftRight","RightHere")

并将其转换为:

>string
[1] "This That"  "One Two"    "Left Right" "Right Here"

我在&#39; stringr&#39;中尝试了很多功能。和&#39; stringi&#39;包。有什么帮助吗?

1 个答案:

答案 0 :(得分:3)

这对你有用吗?

gsub("([A-Z])", " \\1", string) %>% trimws()
[1] "This That"  "One Two"    "Left Right" "Right Here"