I want to run a Reduce code to out1 a list of 66000 list elements:
trialStep1_done <- Reduce(rbind, out1)
However, it takes too long to run. I wonder whether I can run this code with help of a parallel computing package.
I know there is mclapply, mcMap, but I don't see any function like mcReduce in parallel computing package.
Is there a function like mcReduce available for doing Reduce with parallel in R to complete the task I wanted to do?
Thanks a lot @BrodieG and @zheYuan Li, your answers are very helpful. I think the following code example can represent my question with more precision:
df1 <- data.frame(a=letters, b=LETTERS, c=1:26 %>% as.character())
set.seed(123)
df2 <- data.frame(a=letters %>% sample(), b=LETTERS %>% sample(), c=1:26 %>% sample() %>% as.character())
set.seed(1234)
df3 <- data.frame(a=letters %>% sample(), b=LETTERS %>% sample(), c=1:26 %>% sample() %>% as.character())
out1 <- list(df1, df2, df3)
# I don't know how to rbind() the list elements only using matrix()
# I have to use lapply() and Reduce() or do.call()
out2 <- lapply(out1, function(x) matrix(unlist(x), ncol = length(x), byrow = F))
Reduce(rbind, out2)
do.call(rbind, out2)
# One thing is sure is that `do.call()` is super faster than `Reduce()`, @BordieG's answer helps me understood why.
So, at this point, to my 200000 rows dataset, do.call() solves the problem very well.
Finally, I wonder whether this is an even faster way? or the way @ZheYuanLi demostrated with just matrix() could be possible here?