假设矩阵名为mat

n <- ncol(mat) / 5 # 将矩阵按列平均分为5部分 for (j in 1:5) { start_col <- (j-1) * n + 1 end_col <- j * n mat_part <- mat[, start_col:end_col] # 取出当前部分矩阵 for (i in 1:ncol(mat_part)) { mat_part[,i] <- sapply(mat_part[,i], function(x) ifelse(x<=sum(mat_part[,i])*0.0005, 0, x)) # 执行脚本 } mat[, start_col:end_col] <- mat_part # 将处理后的部分矩阵放回原矩阵中 }

R将一个矩阵按列拆分成5部分并分别执行下面脚本:fori in 1ncolphyseq1otu_tablephyseq1otu_tablei - sapplyphyseq1otu_tablei functionx ifelsex=sumphyseq1otu_tablei00005 0 x

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

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