4

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
  • 91,185
  • 12
  • 128
  • 188
user2862862
  • 111
  • 1
  • 1
  • 10

1 Answers1

13

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
  • 306
  • 2
  • 6