如果R

时间:2019-03-14 17:37:53

标签: r duplicates rbind

我有两个数据框,分别显示一个月和下个月的分析结果。

以下是第一个数据集block2:

   Group Count
     589   191
     630    87
     523    77
     581    73
     689    59

Block2是具有当月结果的数据集。仅计数> 0。 Block2_OG是具有上个月结果的数据集。每个组的Block2_OG计数> = 0。我一直在为Block = 0引用Block2_OG,并将它们手动输入到Block2数据集中。我想摆脱本练习的手动部分,只是能够将counts = 0的组附加到此数据集的末尾。我一直在使用上个月的数据集作为添加未包含在本月数据集中的组的参考。

这导致我执行以下代码来执行上述操作:

GData=rbind(block2,block2_OG)
GData=GData[!duplicated(GData$Group),]

虽然此代码产生了更正尺寸,但它并不总是选择要删除的正确副本。有时,它将把当月的结果作为重复项并删除。我只想执行以下操作:

a.) Start with my current month's list (results >0)
b.) Have a complete list from last month (results >=0)
c.) Compare the list from last month to current month
d.) If any group in last month list but not in current list, add that group to current list with a count = 0.

你们可以帮助我修改代码以实现此结果吗?

0 个答案:

没有答案