Say I have this data frame:
Col1 Col2
ABC Hello
ABC Hi
ABC Bye
And want it like this:
Col1 Col2
ABC Hello,Hi,Bye
Say I have this data frame:
Col1 Col2
ABC Hello
ABC Hi
ABC Bye
And want it like this:
Col1 Col2
ABC Hello,Hi,Bye
Here is a solution using dplyr. Should work in general.
library(dplyr)
dat <- data.frame(Col1 = rep("ABC", 3), Col2 = c("Hello", "Hi", "Bye"))
print(head(dat))
dat.merged <- dat %>%
dplyr::group_by(Col1) %>%
dplyr::summarise(Col2 = paste(Col2, collapse = ","))
print(head(dat.merged))