Aggregate to rows according to unique identifier?
I have a data frame that has a unique id (syllable) and a duration. In order to continue my analysis I need to aggregate the data frame by syllable.
This,
syllable duration
ba 0.20414850
a 0.06804950
na 0.11525535
a 0.09877130
na 0.36774874
ba 0.18228837
ba 0.22232325
should look like this:
syllable duration_1 duration_2 duration_3
ba 0.20414850 0.18228837 0.22232325
a 0.06804950 0.09877130
na 0.11525535 0.36774874
I tried to the group_by function of dplyr
library(dplyr)
df %>%
group_by(syllable) %>%
summarise(duration = paste(duration, collapse = ","))
However, this yields:
syllable duration
ba c(0.20414850,0.18228837,0.22232325)
a c(0.06804950,0.09877130)
na c(0.11525535,0.36774874)
Thank you