[R-sig-hpc] .combine in foreach

Jay Emerson jayemerson at gmail.com
Sun Dec 19 16:51:25 CET 2010


.combine=rbind may be helpful in some cases.  However, in a case like
this it wouldn't surprise me if the returns are more complex (like a
list of matrices).  Although I haven't done it, you can write a custom
function for use with .combine (and note the possible need for

You also might be able to use .combine='+'; if the return is a 3x3
matrix, for example, this should give the mean matrix you allude to
below, and would do the addition as the returns occur, avoiding the
storage of all of the matrices.  This is very cool (IMHO).


I?m testing using the foreach package to see if it will parrallelize a
Bayesian MCMC routine.  It appears to work well, just gives back huge
results files when I run multiple iterations.  I?m looking at the
.combine option ... is there an easy way to get it combine the results
across components and still maintain the matrix structure?  Several of
the outputs are 3x3 matrices, but I get 1000 of them, one in each
component.  If possible I?d like to get the mean matrix, i.e  (m1
+m2+m3 ... m1000 ) / 1000  if that makes any sense!?

John W. Emerson (Jay)
Associate Professor of Statistics
Department of Statistics
Yale University

More information about the R-sig-hpc mailing list