0

I have data in this format

data.frame(id = c(1,1,2), 
           date = c("2008-08-04 05:45:07","2008-08-04 09:45:07","2008-08-04 05:45:07"), 
           text = c("stg","another","final"))
#   id                date    text
# 1  1 2008-08-04 05:45:07     stg
# 2  1 2008-08-04 09:45:07 another
# 3  2 2008-08-04 05:45:07   final

How is it possible to merge the rows with the same date into one for the same id. Example of expected output:

data.frame(id = c(1,2), 
           date = c("2008-08-04", "2008-08-04"), 
           text = c("stg another","final"))
#   id       date        text
# 1  1 2008-08-04 stg another
# 2  2 2008-08-04       final
OTStats
  • 1,746
  • 1
  • 11
  • 20
Nathalie
  • 1,188
  • 3
  • 19

1 Answers1

3

You can try aggregate like below

dfout <- aggregate(text ~ date + id, df, paste)

such that

> dfout
  id                date       text
1  1 2008-08-04 05:45:07 stg, final
2  2 2008-08-04 09:45:07    another
ThomasIsCoding
  • 80,151
  • 7
  • 17
  • 65