提取大于1%的行

data_filtered <- data[data$percentage > 1, ]

计算Others行

Others <- colSums(data[!rownames(data) %in% rownames(data_filtered), ])

将Others行添加到data_filtered中

data_filtered["Others", ] <- Others

计算每列的求和并添加到最后一行

data_filtered[nrow(data_filtered) + 1, ] <- colSums(data_filtered)

输出结果

data_filtered

在R语言中data -readcsvPhylumcsvrownames = 1data$percentage - applydata1functionx sumxsumdata100 保留大于1的行其余的行保存为Others并且对每列进行求和写入一行中

原文地址: https://www.cveoy.top/t/topic/feBw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录