[R-sig-hpc] indexing outputs from foreach / doMPI

Maas James Dr (MED) J.Maas at uea.ac.uk
Sun Jan 23 18:57:58 CET 2011


Really struggling with this one,  in a toy example I use the following code.  When I run it a straight R script it works fine, but when  running it within a foreach loop and doMPI backend it re-arranges the outputs.   Is there a way to force foreach to keep all "a" matrices together ... and all the "b" matrices.  I've tried many permutations, no luck yet.

Thanks 

J

=========================



  a <-  apply(results$OR, c(1,2), mean)
  b <- apply(results$OR, c(1,2), sd)

  output <- append (list(a=a),list(b=b))

  return(output)
}

==========================



I get this 

=======================
> stuff
[[1]]
[[1]]$a
         [,1]      [,2]      [,3]
[1,] 1.000000 0.8118515 0.6072900
[2,] 1.236972 1.0000000 0.7499372
[3,] 1.654514 1.3409720 1.0000000

[[1]]$b
           [,1]       [,2]       [,3]
[1,] 0.00000000 0.05265696 0.04191226
[2,] 0.08099146 0.00000000 0.05635320
[3,] 0.11458134 0.10078931 0.00000000


[[2]]
[[2]]$a
         [,1]      [,2]      [,3]
[1,] 1.000000 0.7320218 0.5796935
[2,] 1.371648 1.0000000 0.7942211
[3,] 1.734505 1.2681720 1.0000000

[[2]]$b
           [,1]      [,2]       [,3]
[1,] 0.00000000 0.0462359 0.04265879
[2,] 0.08866844 0.0000000 0.06835189
[3,] 0.12906653 0.1063840 0.00000000

==============================


but I want this ....


>stuff
[[1]]
[[1]]$a
         [,1]      [,2]      [,3]
[1,] 1.000000 0.8118515 0.6072900
[2,] 1.236972 1.0000000 0.7499372
[3,] 1.654514 1.3409720 1.0000000

[[2]]$a
         [,1]      [,2]      [,3]
[1,] 1.000000 0.7320218 0.5796935
[2,] 1.371648 1.0000000 0.7942211
[3,] 1.734505 1.2681720 1.0000000

[[2]]
[[1]]$b
           [,1]       [,2]       [,3]
[1,] 0.00000000 0.05265696 0.04191226
[2,] 0.08099146 0.00000000 0.05635320
[3,] 0.11458134 0.10078931 0.00000000


[[2]]$b
           [,1]      [,2]       [,3]
[1,] 0.00000000 0.0462359 0.04265879
[2,] 0.08866844 0.0000000 0.06835189
[3,] 0.12906653 0.1063840 0.00000000




===============================
Dr. Jim Maas
University of East Anglia



More information about the R-sig-hpc mailing list