2016-04-28 7 views
0

私は3列あります。名前、レビュー、data.frame(セット)データフレーム内の行をマージします。[一部のフィールドは重複しています]

 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

ロジックは何ですか? – akrun

答えて

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  
+0

2行と3行は必要ありません。データは1行目のみで結合されます。 私は一番上に示します。それらをチェックしてください。おかげで – Rajesh

+0

'df $ review [1] < - paste(df $ review、collapse ="; ")' と 'df [1、]' – mtoto

+0

ありがとうございました。 – Rajesh

-1

を仮定すると、 "レビュー" 欄には、因子のタイプである

require(plyr) 
df$review <- as.character(df$review) 

ddply(df, .(name, part), summarize, review = paste(review, collapse = " "))[,c(1,3,2)] 
+0

ありがとうあなたの答えも良いです。ありがとう。 – Rajesh

関連する問題