【发布时间】:2017-05-01 13:22:50
【问题描述】:
我使用聚合函数来总结重复行和唯一行,并在两个数据帧(df 和 nm)中找到公共列的平均值,即
df
User Apple Cherry Kiwi Lemon
A 208 71 129 58
B 81 69 142 53
C 164 212 175 200
D 125 73 51 214
E 205 123 46 75
F 53 215 40 38
nm
User Lemon Cherry Apple Kiwi
A 161 57 27 38
B 26 153 57 45
C 39 153 219 86
D 47 155 139 61
kl = aggregate(.~User, data=rbind(df, nm[, match(colnames(df), colnames(nm))]), FUN=mean)
它显示重复行和唯一行的输出。
kl
User Apple Cherry Kiwi Lemon
A 117.5 64 83.5 109.5
B 69 111 93.5 39.5
C 191.5 182.5 130.5 119.5
D 132 114 56 130.5
E 205 123 46 75
F 53 215 40 38
But wanted output of only duplicated rows i.e. unique rows should be removed.
kl
User Apple Cherry Kiwi Lemon
A 117.5 64 83.5 109.5
B 69 111 93.5 39.5
C 191.5 182.5 130.5 119.5
D 132 114 56 130.5
我怎样才能使用上面的公式来做到这一点。
我试图找到这个答案,但到处都显示了重复和独特的示例。
请提供解决方案!!
谢谢
【问题讨论】:
标签: r