折叠R中的分层比例

时间:2017-01-12 21:10:09

标签: 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 Deltaprot Desulf uncl_Desulf                 1.922%
Bac prot Deltaprot Desulf                             2.311%
Bac prot Deltaprot                                    2.333%
Bac prot                                              2.517%

如果您注意到,百分比"堆叠"。因此,Desulfovibrio的百分比包含在Bac prot的总体百分比中。

我想将其分开,任何不包含在基本排名中的内容都将采用"未分类_"。

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

有谁知道比写for循环更简单的方法吗?

0 个答案:

没有答案