我有 17 个文件支持的 big.matrix 对象(暗淡 10985 x 52598,每个 4.3GB),我想计算其中的元素平均值。结果可以存储在另一个big.matrix(gcm.res.outputM)中。
biganalytics::apply() 不起作用,因为 MARGIN 只能设置为 1 或 2。我尝试使用 2 个 for 循环,如下所示
gcm.res.outputM <- filebacked.big.matrix(10958, 52598, separated = FALSE, backingfile = "gcm.res.outputM.bin", backingpath = NULL, descriptorfile = "gcm.res.outputM.desc", binarydescriptor = FALSE)
for(i in 1:10958){
for(j in 1:52598){
t <- rbind(gcm.res.output1[i,j], gcm.res.output2[i,j],gcm.res.output3[i,j], gcm.res.output4[i,j],
gcm.res.output5[i,j], gcm.res.output6[i,j],gcm.res.output7[i,j], gcm.res.output8[i,j],
gcm.res.output9[i,j], gcm.res.output10[i,j],gcm.res.output11[i,j], gcm.res.output12[i,j],
gcm.res.output13[i,j], gcm.res.output14[i,j],gcm.res.output15[i,j], gcm.res.output16[i,j],
gcm.res.output17[i,j])
tM <- apply(t, 2, mean, na.rm = TRUE)
gcm.res.outputM[i,j] <- tM
}
}
每行 i 大约需要 1.5 分钟,因此运行时间约为 11 天。
有谁对如何加快计算速度有任何想法?我使用的是 64x Windows10 计算机,内存为 16GB。
Thanks!