I have quite messy data imported from json file, it looks like this:
raw_df <- data.frame(text = c(paste0('text', 1:3), '---------- OUTCOME LINE ----------', paste0('text', 4:6), '---------- OUTCOME LINE ----------'),
demand = c('cat1', rep('', 2), 'info', 'cat2', rep('', 2), 'info2')
)
raw_df
text demand
1 text1 cat1
2 text2
3 text3
4 ---------- OUTCOME LINE ---------- info
5 text4 cat2
6 text5
7 text6
8 ---------- OUTCOME LINE ---------- info2
(BTW, ---------- OUTCOME LINE ---------- is the actual string that I have in text column)
I want to tidy it up so that it has the following format:
final_df
text demand outcome
1 text1. text2. text3. cat1 info1
2 text4. text5. text6. cat2 info2
What would be the quickest and most efficient way to do this? thanks for the tips.