I have a vector called chapt1. I want to reorganize this vector into a data frame, df1 such that;
- The integers(the ones in parenthesis) beginning each verse is printed in the first column of
df1- The adjoining text is printed in the next column on the same row.
chapt1 <- ("1. The Grand Opening (35) The black cat jumped over the
lazy rabbit. (36) Salt has no taste (37) The grandmaster mentors his
disciples (1) Generation of miracles. (2) Are we there yet:
opening the first stage in the dungeon.")
Result;
35 The black cat jumped over the lazy rabbit.
36 Salt has no taste
37 The grandmaster mentors his disciples.
1 Generation of miracles.
2 Are we there yet: opening the first stage in the dungeon.
Note: This is just a portion of the original file.
Edit: How do I make sure that the row numbers follow the same numbering as the integers in the string.
I've tried
timtim <- as_tibble(chapt3) %>%
separate_rows(value, sep = '\\(\\b([0-9]|[1-9][0-9])\\)') %>%
filter(row_number() > 1) %>%
mutate(value = str_squish(value))
But the row numbering keeps coming out in alphabetical order. Thanks in advance.