【发布时间】:2020-08-21 18:19:47
【问题描述】:
我有一个 Rna-seq 数据集(行 = 样本,列 = 基因),它进入了一个聚类函数。这些基因被分成n个用数字标记的簇,其中属于簇0的基因是非簇基因。聚集的那些又回到聚集中,我们再次得到 n 个用数字标记的簇,其中 0 再次是非聚集基因。该过程继续进行,直到没有进一步的基因被分类到集群 0 中。我需要循环进入这个过程,以便在每次迭代时返回最终的集群结果以及属于集群 0 的基因的联合。我知道这可以通过 while 或 repeat 来完成。我曾尝试使用 repeat 但无法正常工作,问题是我还不清楚如何正确设置。
#define my dataset
dat<-my_dataset
repeat{
#run the clustering
aa<-cluster(dat)
#if the cluster 0 has length 0 (no genes), assign clustering results to Mod and stop the loop
if (length(which(aa$colors==0))==0){
Mod<-aa
break
#otherwise, store the genes belonging to cluster 0 and set up a new dataset made up by clustered genes
} else{
noPass<-rownames(dat)[aa$colors==0]
dat<-dat[,which(aa$colors!=0)]
}
return(list(aa,noPass))
}
非常感谢任何建议。
【问题讨论】:
标签: r loops while-loop