I have a dataset that is structured like this:
book | chapter | verse | text |
---|---|---|---|
1 | 1 | 1 | string1 |
1 | 1 | 2 | string2 |
1 | 2 | 1 | string3 |
1 | 2 | 2 | string4 |
2 | 1 | 1 | string5 |
2 | 1 | 2 | string6 |
2 | 2 | 1 | string7 |
2 | 2 | 2 | string8 |
And my intended output is:
book | chapter | text |
---|---|---|
1 | 1 | string1 string2 |
1 | 2 | string3 string4 |
2 | 1 | string5 string6 |
2 | 2 | string7 string8 |
I tried it with the line below, but then it sums up all chapters with the same number regardless of the book number.
df %>% group_by(chapter) %>% summarise(text = paste(text, collapse=", "))
I am using tidyr. Any help is much appreciated.