【发布时间】:2014-07-03 16:01:36
【问题描述】:
在R 中对data.frame 执行类似连接操作的最快方法是什么?假设我有下表:
df <- data.frame(content = c("c1", "c2", "c3", "c4", "c5"),
groups = c("g1", "g1", "g1", "g2", "g2"),
stringsAsFactors = F)
df$groups <- as.factor(df$groups)
我想按组高效地连接content 列中单元格的内容,以接收相当于:
df2 <- data.frame(content = c("c1 c2 c3", "c4 c5"),
groups = c("g1", "g2"),
stringsAsFactors = F)
df2 $groups <- as.factor(df2 $groups)
我更喜欢一些dplyr 操作,但不知道如何应用它。
【问题讨论】:
标签: r dataframe concatenation aggregate dplyr