mikeymike
mikeymike

Reputation: 75

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:

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

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

Upvotes: 0

Views: 38

Answers (1)

Nate
Nate

Reputation: 10671

does this work for you?

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

Upvotes: 3

Related Questions