A while ago I asked for help on how to do the reverse of what I want to do now, this discussion can be found here. Anyway, I now need to join my data back into the format it once was. That is, to join the separate rows (each containing a word), into one sentence per ID. For example:
Input:
id word
1 Lorem
1 ipsum
1 dolor
1 sit
1 amet
2 consectetur
2 adipiscing
2 elit
3 Donec
...
Output:
id text
1 Lorem ipsum dolor sit amet
2 consectetur adipiscing elit
3 Donec euismod enim quis
4 nunc fringilla sodales
5 Etiam tempor ligula vitae
6 pellentesque dictum
At first, I tried to do this with the reshape
package and its melt()
and cast()
functions. I also tried the tidyr
package. However, these functions rely on a variable name column specifying the column name for each of the new columns. Not exactly my case (and each sentence can be of different length).
How can I do this task in R
?