2

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  
thelatemail
  • 85,757
  • 12
  • 122
  • 177
user2862862
  • 81
  • 1
  • 9

1 Answers1

10

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))
jakeyeung
  • 176
  • 1
  • 6