I have a data frame that looks like the example below.
| element | string |
|---|---|
| x | abc |
| y | def |
| z | ghi |
| z | jkl |
| x | mno |
| y | pqr |
| z | stu |
| x | vwx |
| y | yza |
| z | bcd |
| z | efg |
| z | hij |
| x | klm |
| y | nop |
| z | qrs |
| z | tuv |
| z | wxy |
All the strings in the string column vary but the values in the element column always follow an x-y-z pattern, although the number of z's varies. I would like to take the strings in the strings column from each x-y-z set and concatenate them - so the strings column in the dataframe above would look like this:
| string |
|---|
| abc def ghi jkl |
| mno pqr stu |
| vwx yza bcd efg hij |
| klm nop qrs tuv wxy |
I was thinking there might be a way to do this using dplyr::rowwise? The variable # of z rows per each set is tripping me up though in figuring out something that might work...