When I want to do some operation over the lists, and get the list with the same names as a result I use sapply function:
当我想对列表进行一些操作,并获得具有相同名称的列表时,我使用sapply函数:
newList <- sapply(oldList, someFunction, simplify = FALSE,USE.NAMES = TRUE)
Is it possible (and how) to do the same using parallel versions of function from apply family, eg mclapply from parallel package?
是否有可能(以及如何)使用apply系列的并行版本的函数来做同样的事情,例如来自并行包的mclapply?
2 个解决方案
#1
1
?mclapply
help page says that this is possible (argument SIMPLIFY
), although only for mcmapply
. As you've already figured it out, (mc)mapply
with only one object passed is a special case and is equivalent to (mc)lapply
.
?mclapply帮助页面说这是可能的(参数SIMPLIFY),虽然仅适用于mcmapply。正如你已经想到的那样,(mc)mapply只传递一个对象是一个特例,相当于(mc)lapply。
#2
0
There is parSapply function in parallel package - https://stat.ethz.ch/R-manual/R-devel/library/parallel/html/clusterApply.html
并行包中有parSapply函数 - https://stat.ethz.ch/R-manual/R-devel/library/parallel/html/clusterApply.html
library("parallel")
cl <- makeCluster(getOption("cl.cores", 2))
newList <- parSapply(cl, oldList, someFunction, simplify = FALSE,USE.NAMES = TRUE)
#1
1
?mclapply
help page says that this is possible (argument SIMPLIFY
), although only for mcmapply
. As you've already figured it out, (mc)mapply
with only one object passed is a special case and is equivalent to (mc)lapply
.
?mclapply帮助页面说这是可能的(参数SIMPLIFY),虽然仅适用于mcmapply。正如你已经想到的那样,(mc)mapply只传递一个对象是一个特例,相当于(mc)lapply。
#2
0
There is parSapply function in parallel package - https://stat.ethz.ch/R-manual/R-devel/library/parallel/html/clusterApply.html
并行包中有parSapply函数 - https://stat.ethz.ch/R-manual/R-devel/library/parallel/html/clusterApply.html
library("parallel")
cl <- makeCluster(getOption("cl.cores", 2))
newList <- parSapply(cl, oldList, someFunction, simplify = FALSE,USE.NAMES = TRUE)