【发布时间】:2014-03-31 06:20:01
【问题描述】:
我有两个数据框
distinct_paper_year_data:
author_id distinct_paper_year_count
1 3
2 1
4 1
5 4
作者数据:
author_id paper_id confirmed
1 25733 1
2 47276 1
3 79468 1
4 12856 0
现在我想合并,以便所需的输出如下所示:
author_id paper_id confirmed distinct_paper_year_count
1 25733 1 3
2 47276 1 1
3 79468 1 0
4 12856 0 4
在此,我需要在表 author_data 中出现的 author_ids 出现在最终输出中。由于 distinct_paper_year_count 中没有 author_id==3 的数据,因此 distinct_paper_year_count 列的值在最终结果中应为零(对于 author_id==3)。
通过使用合并我得到了
merge(distinct_paper_year_data,author_data,by="author_id")
author_id distinct_paper_year_count paper_id confirmed
1 3 25733 1
2 1 47276 1
4 1 12856 0
怎样才能达到想要的输出?
【问题讨论】: