I would like to know if two different objects can be output after using the foreach %dopar% foreach .
I will try to explain what I am looking for. Suppose I have two data.frames as a result of several operations inside a loop:
library(doMC) library(parallel) registerDoMC(cores=4) result <- foreach(i=1:100) %dopar% {
My desired result would be a list of data.frames of length 2, for example:
dim(result[[1]])
I tried using this from a previous post Saving multiple outputs of a foreach dopar loop :
comb <- function(x, ...) { lapply(seq_along(x), function(i) c(x[[i]], lapply(list(...), function(y) y[[i]]))) result <- foreach(i=1:100, .comb='comb', .multicombine=TRUE) %dopar% {
But this does not give the expected result.
When I do the following:
result <- foreach(i=1:100, .comb=cbind) %dopar% {
I get only data.frame vec2 . Is there a way to return or save both outputs?
thanks
foreach parallel-processing r
user2380782
source share