Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

R Splitting strings by multiple splitting criteria and storing the splitting criteria

$
0
0

I'm trying to split a string by multiple criteria and store the splitting criteria for each split.

I have been trying to use the stringr::str_split package but cannot pass more than one splitting criteria to the function.

For example if I have the following string:

data = "Julie (title) : This is the text Julie has: said. Extra sentence one. Extra sentence 2 and so on. Rt Hon Ellen: This is the text Ellen has said in response to Julie. TITLE OF SECTION Julie: More words from Julie."

and splitting criteria:

names = c("Julie:", "Ellen:")

I would like an output like this:

data.frame(Names = c("Julie:", "Ellen:","Julie:"),
           text = c(" This is the text Julie has: said. Extra sentence one. Extra sentence 2 and so on. ", "This is the text Ellen has said in response to Julie.","More words from Julie."))

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>