0

I have a dataset:

ID WhereEaten
1 restaurant
1 home
2 hospital
3 camp
4 restaurant
4 grocery store

I want to merge the rows by ID, and combine the values of WhereEaten to look like this:

ID WhereEaten
1restaurant, home
2 hospital
3 camp
4 restaurant, grocery store

Any help is appreciated. Thanks!

  • 1
    You can do `aggregate(WhereEaten~ID, df, toString)` – akrun Mar 02 '18 at 14:56
  • Thanks akrun. This did not work for me, and neither did the suggestion from the other post. This is what I did... aggregate(Query1$WherePrepName~Query1$CDCID, Query1, toString) Query1 library(plyr) ddply(Query1, .(CDCID), summarize, WherePrepName = toString(WherePrepName)) Query1 – Rachel Silver Mar 02 '18 at 15:31
  • From the example you posted, it is working fine for me – akrun Mar 03 '18 at 01:12

0 Answers0