我有3列。 name,review,part in data.frame(set)
name review part
1 abc this is good cap
2 abc this is not bad cap
3 abc this is also good cap
我希望最终结果如下:
name review part
1 abc this is good this cap
is not bad this is
also good
答案 0 :(得分:2)
假设您的列属于character
类,您可以执行以下操作:
df[sapply(df, duplicated)] <- ""
> df
# name review part
#1 abc this is good cap
#2 this is not bad
#3 this is also good
答案 1 :(得分:-1)
假设“审核”列是因子类型
require(plyr)
df$review <- as.character(df$review)
ddply(df, .(name, part), summarize, review = paste(review, collapse = " "))[,c(1,3,2)]