[R] apply to multiple arrays simultaneously

Carlos Soares csoares at liacc.up.pt
Fri Jan 9 11:10:03 CET 2004

Dear R users,
Suppose two arrays which partly have the same dimensions. For instance, 
a1 and a2 with dim(a1) is c(3,4,5,6) and dim(a2) is c(3,4,7,8). How can 
I perform an apply on the equivalent part of the dimensions on both 
arrays simultaneously? Something like:
  apply(list(a1, a2), c(1,2), function(x,y) {my.function(x,y)})
A useful bonus would be, assuming that my.function always returns an 
array withthe same dimensions (e.g., c(2,3,4), that the final result 
would be an array wit
h dimensions c(3,4,2,3,4).
With best regards,

More information about the R-help mailing list