'How to aggregate the rows with text grouping them by date in R?

To give an example, I have a table like this one: enter image description here

But I would like to have a table like this one: enter image description here



Solution 1:[1]

Do you need this? group_by with summarise and toString():

library(dplyr)
# your dataframe
Date <- c("30/05/2020", "30/05/2020", "30/05/2020",
          "29/05/2020", "29/05/2020")
Text <- c("Here we are", "He likes ABC", "She likes DEF",
          "Cat eats XYZ", "I have a pet")

df <- data.frame(Date, Text)


df %>% 
  group_by(Date) %>% 
  summarise(Text = toString(Text))

output:

  Date       Text                                    
  <chr>      <chr>                                   
1 29/05/2020 Cat eats XYZ, I have a pet              
2 30/05/2020 Here we are, He likes ABC, She likes DEF

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TarJae