我很抱歉,因为我知道这个问题以前有人问过,但我尝试了大多数答案的变体,但没有帮助。
我正在使用 foreach 包对一组数据运行 NMF 算法的循环。我正在尝试使用 ExtractFeatures 函数提取基础名称集,该函数将每次运行输出为您确定的排名数的列表(在我的示例中为 3)。
这是我下面的代码(我使用了 NMF 晕影中的示例数据集):
library("NMF")
library("doParallel")
library("foreach")
#load vignette dataset and shorten it for time's sake
data(esGolub)
esGolub <- esGolub[1:200,]
#output matrix
Extract_Genes <- matrix()
#set cores
registerDoParallel(cores = 3)
#Loop NMF runs and extract features
foreach(i =1:4, .packages = "NMF") %dopar%{
i <- nmf(esGolub, 3, nrun = 1)
Extract_Genes <- extractFeatures(i, format = "list")
}
这将输出提取的基因列表,如下所示:
[[1]]
[[1]][[1]]
[1] 43 120 128 130
[[1]][[2]]
[1] 94 1 112 42 8 64 96 182 59 41 69 25 26
[[1]][[3]]
[1] 39 74 2 91 190 167 103 129 174
3 次运行 3 次,但它没有保存。有人对如何保存这些输出有任何建议吗?
提前谢谢你,J
Imo 的评论工作正常:
myList <- foreach(i =1:4, .packages = "NMF") %dopar%{