#根据OTU算top100菌群相对丰度值
library(tidyverse)
rm(list=ls())
df<-read.csv("1.csv",header=TRUE,row.names=1,
stringsAsFactors=FALSE)
head(df)
sample<-colnames(df)[sapply(df,is.numeric)]
sample
temp<-df[,sample]
df$sum<-rowSums(temp,na.rm=T)
df<-df[order(df$sum,decreasing=T),]
df1<-df[1:100,]
df1<-na.omit(df1)
df2<-df[100+1:nrow(df),]
df1["Others",]<-colSums(df2,na.rm=T)
df_per<-sweep(df1,2,colSums(df),"/")
df_per1<-df_per*100
write.csv(df_per1,"top100.csv")
暂无评论