-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Prof
Brian Ripley
Sent: Wednesday, March 31, 2004 10: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 you intended.
On Wed, 31 Mar 2004, Tamas Papp wrote:
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.
Why do you think is `not that efficient'? Does you have a
need to save
microseconds?
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595