我有一个看起来像表
的数据集
我需要根据第一列中的内容组合内容。 这就是我想要的数据:
答案 0 :(得分:0)
# 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