[R] array addition doesn't recycle!

Tamas Papp tpapp at axelero.hu
Wed Mar 31 16:25:03 CEST 2004


Hi,

I have noticed the following:

> a <- array(1:4, c(2, 2))
> A <- array(1:4, c(2,2,2))
> A + a
Error in A + a : non-conformable arrays

It works with a matrix + a vector, why doesn't it work with arrays?
Am I missing something?

How would you do the above operation efficiently (ie I need to add a
matrix to each "plane" of 3-dim array)?  At the moment I am using
something like

A + array(a, c(2,2,2))

but it doesn't seem that efficient.

Thanks

Tamas

-- 
Tamás K. Papp
E-mail: tpapp at axelero.hu (preferred, especially for large messages)
        tpapp at westel900.net
Please try to send only (latin-2) plain text, not HTML or other garbage.




More information about the R-help mailing list