2

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

claudia
  • 23
  • 2
  • (1) Hi there and welcome to Stack Overflow. (2) Please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) or [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with a sample input (not posted in an image) and your expected output. This is needed to create, test and verify possible solutions. (3) Please describe the main difference between the two images you included in your question. How do you want the `Text` column to be handled? – Martin Gal Apr 08 '22 at 23:36
  • you should probably also add a bit of info on the way you expect the other two rows for the first date to go within the same cell or as additional columns, since that is not clear from the second screenshot? plus you should give the `reprex` R package a try – GWD Apr 08 '22 at 23:37

1 Answers1

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
TarJae
  • 72,363
  • 6
  • 19
  • 66