Use multiple arguments in mclapply

How can I use mclapply over two lists as in the following function

f1 <-list(sample(5),
          sample(4),
          sample(2))

f2 <-list(sample(5),
          sample(4),
          sample(2))


func=function(x,y){
  z=2*x+y
  return(z)
}

mclapply:

parallel::mclapply( f1,f2,function(x,y){
  return(func(x,y))
}, mc.cores=1)

I believe you want mcmapply the parallel version of mapply. Note that the arguments are in a different order with mapply.

parallel::mcmapply(function(x,y){
    return(func(x,y))
}, x = f1, y = f2, mc.cores=1)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.