Skip to content

(hopefully) simple array op

2 messages · Cable, Samuel B Civ USAF AFMC AFRL/RVBXI, Baptiste Auguie

#
I have a multidimensional array "a", for example,
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

So a is 2x2x2.

I have another array "b", for example,
[,1] [,2]
[1,]    9   11
[2,]   10   12

So b is 2x2.

I want to "tack" b onto a so that b becomes a new "plane", so to speak,
in a.  In other words, I want the result c to be:
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

, , 3

     [,1] [,2]
[1,]    9   11
[2,]   10   12

I can think of a number of ways to do this, but they are all cumbersome.
Given R's facility with arrays and indices, it occurs to me that there
might be some "one-line" way to accomplish this.  Does anyone know if
there is?  Thanks.

--Sam
#
Do you want abind?

http://cran.r-project.org/web/packages/abind/index.html

baptiste

On 15 Apr 2009, at 19:33, Cable, Samuel B Civ USAF AFMC AFRL/RVBXI  
wrote:
_____________________________

Baptiste Augui?

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag