0

I have the next table

tb <- data.frame(Name=c(rep("John",4),rep("Peter",2),rep("Mary",3)),
             Char=c("CharA","CharB","Charc","CharD","CharB","CharE","CharA","CharC","CharD")
             )

Is it possible to create a table like this to summarize the information in the second column per Name?.

 tb.res <- data.frame(Name=c("John","Peter","Mary"),
                 Resume=c("CharA,CharB,CharC,CharD","CharB,CharE","CharA,CharC,CharD"))
jccigh
  • 37
  • 1
  • 6

1 Answers1

3

You could try

library(data.table)
setDT(tb)[, list(Resume=toString(Char)), Name]

Or use aggregate from base R

aggregate(Char~Name, tb, paste, collapse=',')
akrun
  • 874,273
  • 37
  • 540
  • 662