[R] apply to multiple arrays simultaneously
Carlos Soares
csoares at niaad.liacc.up.pt
Fri Jan 9 15:14:02 CET 2004
abind only allows one of the dimensions to be different. In may case
they differ on several dimensions. For instance, in the example I gave
(which was probably not clear enough), I would like
my.function to be called 3*4 times, each time being passed 2 matrices x
and y with dim(x)=c(5,6) and dim(y)=c(7,8).
Anyway, thanks for the tip, Andy.
Carlos
Liaw, Andy wrote:
>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, contains
>information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New
>Jersey, USA 08889), and/or its affiliates (which may be known outside the
>United States as Merck Frosst, Merck Sharp & Dohme or MSD) that may be
>confidential, proprietary copyrighted and/or legally privileged, and is
>intended solely for the use of the individual or entity named on this message.
>If you are not the intended recipient, and have received this message in
>error, please immediately return this by e-mail and then delete it.
>------------------------------------------------------------------------------
>
>
More information about the R-help
mailing list