我有以下数据框。
x <- data.frame("Item" = c('Item1','Item1','Item2','Item2'), "Name" = c("This row and","the next should be grouped together","Also this row and","the next should be grouped together"))
我希望输出如下。
x2 <- data.frame("Item" = c('Item1','Item2'), "Name" = c("This row and the
next should be grouped together","Also this row and the next should be
grouped together"))
我有10000行的大型数据框,对R还是陌生的。
答案 0 :(得分:1)
您可以使用dplyr
并将Item
变量分组并连接文本。我用空字符串但','或';'折叠了也是可能的
library(dplyr)
x %>%
group_by(Item) %>%
summarise(Name=paste0(Name, collapse=''))