mike805 mike805 - 1 year ago 104
R Question

Splitting conjoining words in R

I am trying to split string that is structured like:

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

and turn it into:

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

I have tried numerous functions in the 'stringr' and 'stringi' package. Any help?

Answer Source

does this work for you?

gsub("([A-Z])", " \\1", string) %>% trimws()
[1] "This That"  "One Two"    "Left Right" "Right Here"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download