RE: [R] array addition doesn't recycle!

2004-04-01 Thread Robin Hankin
At 01:39 pm -0500 31/03/04, Raubertas, Richard wrote: Another alternative is to use the underappreciated function 'sweep()': sweep(A, 1:2, a, +) I find the following helpful (it's not due to me but I cannot find the original poster): %.+% - function(a,x){sweep(a , 2:1 , x ,+ )} %+.% -

[R] array addition doesn't recycle!

2004-03-31 Thread Tamas Papp
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

RE: [R] array addition doesn't recycle!

2004-03-31 Thread Raubertas, Richard
:00 AM To: Tamas Papp Cc: R-help mailing list Subject: Re: [R] array addition doesn't recycle! The recycling rules are documented and this is not amongst them. Computer packages do have a tendency to follow their rules rather than read your mind. I suspect A + as.vector(a) is what