mike805 mike805 - 10 months ago 92
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"