I have a dataset that looks like the table
I need to combine the content based on content in the first column. This is how I want my data to be:
I have a dataset that looks like the table
I need to combine the content based on content in the first column. This is how I want my data to be:
# install.packages(c("tidyverse"), dependencies = TRUE)
library(tibble)
tbl <- tibble(Name = c(rep('Jack', 3L), rep('Ann', 2L)),
Message = c('Hello', 'How are you?', 'Nice to meet you', 'Hi', "I'm fine"))
tbl
#> # A tibble: 5 x 2
#> Name Message
#> <chr> <chr>
#> 1 Jack Hello
#> 2 Jack How are you?
#> 3 Jack Nice to meet you
#> 4 Ann Hi
#> 5 Ann I'm fine
library(dplyr)
aggregate(Message ~ Name, tbl, paste, collapse = ' ') %>% arrange(desc(Name))
#> Name Message
#> 1 Jack Hello How are you? Nice to meet you
#> 2 Ann Hi I'm fine