[R] apply to multiple arrays simultaneously

Liaw, Andy andy_liaw at merck.com
Fri Jan 9 14:39:43 CET 2004


Off the top of my head, seems like you can abind() the two together and then
run apply.  See the abind package on CRAN.

HTH,
Andy

> From: Carlos Soares
> 
> 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,
> Carlos


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}




More information about the R-help mailing list