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
Hi Robin, I wrote myself a function "abind" to do this a while ago. I have not used it recently but I am attaching the code and man page for you to have a look at. Cheers, Jonathan. Robin Hankin wrote:> 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.> [snip] -- Jonathan Rougier Science Laboratories Department of Mathematical Sciences South Road University of Durham Durham DH1 3LE tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388 http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: abind.R Url: https://stat.ethz.ch/pipermail/r-help/attachments/20021210/b1c3d576/abind.pl -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: abind.Rd Url: https://stat.ethz.ch/pipermail/r-help/attachments/20021210/b1c3d576/abind-0001.pl