library(parallel) cl <- makeCluster(detectCores()) # 创建并行计算集群 clusterEvalQ(cl, library("phyloseq")) # 在集群中加载所需要的包

定义需要并行化的函数

my_fun <- function(x, physeq) { ifelse(x <= sum(physeq@otu_table[,i])*0.0005, 0, x) }

并行化循环

result <- parApply(cl, physeq1@otu_table, 2, function(x) sapply(x, my_fun, physeq1))

stopCluster(cl) # 关闭集群

更新physeq1

physeq1@otu_table <- as.matrix(result)

使用parallel包并行下面脚本:fori in 1ncolphyseq1otu_tablephyseq1otu_tablei - sapplyphyseq1otu_tablei functionx ifelsex=sumphyseq1otu_tablei00005 0 x

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

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