[R] generalized cbind()

Robin Hankin r.hankin at auckland.ac.nz
Mon Dec 9 23:44:02 CET 2002


Hello Rexperts

If I have an array "a" with a <- array(1:8,c(2,2,2)) then there are
three ways of putting "a" together with another version of "a", one
for each dimension.

The first way is easy:

 array(c(a,a),c(2,2,4))
, , 1

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

, , 2

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

, , 3

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

, , 4

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

[that is, just a and then another a in positions [,,1:2].  Is there an
easy way to create the equivalent thing but joined along another
dimension?  The other two would be:


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

, , 2

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


and



, , 1

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

, , 2

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


Does anyone know of a function that would do this? It would ideally be
called like


R> join(a,a,dimension=3)



-- 

Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042

as of: Tue Dec 10 11:32:00 NZDT 2002
This (linux) system up continuously for:  467 days, 17 hours, 14 minutes




More information about the R-help mailing list