首页 > 解决方案 > 如何合并重复项

问题描述

我在数据集中有几个重复的条目。我想组合然后将结束列添加在一起。见下文。

我有的:

Main | FLOW22016| FLOW2| Forest Lakes| 2016| 2016-10-03| 0| Creek chub| Semotilus atromaculatus| 1|

Main | FLOW22016| FLOW2| Forest Lakes| 2016| 2016-10-03| 0| Creek chub| Semotilus atromaculatus| 1|

我想要的是

Main | FLOW22016| FLOW2| Forest Lakes| 2016| 2016-10-03| 0| Creek chub| Semotilus atromaculatus | 2|

这可能吗?我有很多这样的数据点,我想结合起来。

标签: rdataframeduplicates

解决方案


尝试,

library(dplyr)

df %>%
  group_by(across(c( - lastcolumn))) %>%
  summarise(lastcolumn = n())

哪里lastcolumn是 1 并且需要变为 2 的列。


推荐阅读