折叠R中的分层比例

折叠R中的分层比例,r,data-cleaning,R,Data Cleaning,我有一个数据集,每个小节都有累积的总和,我想把它折叠起来,使总和只反映基本水平的数额。例如,我的当前数据集如下所示: Bac prot Deltaprot Desulf Desulfacaea Desulfovibrio 0.156% Bac prot Deltaprot Desulf Desulfacaea Bilophila 0.171% Bac prot Deltaprot Desulf Desulfacaea 0.391% Bac prot

我有一个数据集,每个小节都有累积的总和,我想把它折叠起来,使总和只反映基本水平的数额。例如,我的当前数据集如下所示:

Bac prot Deltaprot Desulf Desulfacaea Desulfovibrio   0.156%
Bac prot Deltaprot Desulf Desulfacaea Bilophila       0.171%
Bac prot Deltaprot Desulf Desulfacaea                 0.391%
Bac prot Deltaprot Desulf uncl_Desulf                 1.922%
Bac prot Deltaprot Desulf                             2.311%
Bac prot Deltaprot                                    2.333%
Bac prot                                              2.517%
如果您注意到,百分比“堆叠”。因此,脱硫弧菌的百分比包含在Bac蛋白的总百分比中

我想把它分开,任何不包括在基本排名中的东西都会被归类为“未分类”

因此,例如,未进一步细分的Desulfacea条目需要更改为未分类的Desulfacea子集,百分比为0.391%-(0.156%+0.171%)或0.064%

有人知道比为循环编写代码更简单的方法吗