【发布时间】:2015-11-16 15:54:21
【问题描述】:
我在使用 R 和 foreach 包进行并行处理时遇到了这个问题。
我每小时有一个数据集,为期一年。只考虑一个数据集,我使用并行运行:
day = foreach (h = 1:24, .combine=rbind) %dopar% {
...
singlematrix # return a single matrix
}
24matrices <- day
# thanks to rbind, all single matrices are piled together
每个循环都返回一个矩阵,.combine=rbind 使我得到一个更大的矩阵,即24个单个矩阵堆积起来。
如果不是在每个 h 处返回一个矩阵,我想实现类似:
day = foreach (h = 1:24, .combine=rbind) %dopar% {
...
list("row"=singlerow, "matrix"=singlematrix) # return both
}
24rows <- day[[1]] # singlerows piled up
24matrices <- day[[2]] # singlematrices piled up
如何在不混合行和矩阵的情况下将所有 24 个单行和所有 24 个单矩阵堆叠在一起?
我尝试插入.multicombine=TRUE,返回list( "row"=item1, "matrix"=item2),但行和矩阵混合在一起。不幸的是,我不擅长lapply,这可能是这里的路。
非常感谢!
【问题讨论】:
标签: r list foreach lapply rbind