[R] combining two (or more) tables by creating another dimension

Bill.Venables at csiro.au Bill.Venables at csiro.au
Thu Apr 24 00:53:59 CEST 2008


if(!require(abind)) {
	install.packages("abind") 
	library(abind)
}

t3 <- as.table(abind(t1, t2, rev.along = 0))

###  why must they be tables?


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Georg Ehret
Sent: Thursday, 24 April 2008 6:27 AM
To: r-help
Subject: [R] combining two (or more) tables by creating another
dimension

Dear R community,     I wish to combine two tables in one by adding an
additional dimension:

e.g.:
>
t1<-as.table(matrix(rnorm(40),nrow=4,ncol=10));rownames(t1)<-c("rowone",
"rowtwo","rowthree","rowfour")
> t1
                   A           B           C           D           E
  F           G           H           I           J
rowone   -1.04203810 -0.05148987 -1.74162922  0.02683198 -0.28622512
-0.87690444 -0.12335543 -0.60394319 -0.15923255  0.53235864
rowtwo   -1.01168507  1.07785313 -0.17483300 -0.60747916  1.12944895
 0.89512881  0.13972544  0.05006999  1.08190614  1.65985042
rowthree -1.52667891 -0.50032166  2.04588634 -1.55943514  1.58400939
-0.03039314 -0.21145199  0.11526848  2.24376313 -0.74787863
rowfour   0.39287271 -0.55125576 -0.74755340 -1.73366333  0.18886435
 0.60942387  1.03573198 -1.93694305  0.32919872 -0.09073655
>
t2<-as.table(matrix(rnorm(40),nrow=4,ncol=10));rownames(t1)<-c("rowone",
"rowtwo","rowthree","rowfour")
> t2
            A           B           C           D           E
F
        G           H           I           J
A -0.23533769 -1.13888448  0.33531402  0.53159432  0.37499285
0.14237453
 0.38195561 -1.06769856 -0.43285636  0.50321651
B -1.96015770 -0.70381431  0.24031069 -0.65790501 -0.87634039
0.26629589
 0.66948553 -0.78660318  0.86132576 -1.03440605
C  1.48375673 -0.07710868 -0.18416378 -2.39868210 -0.09285612
0.88384443
 1.34379990  1.15250558 -1.26557860 -0.63810608
D -1.45636216  0.03015655  1.68455454  1.19187925  0.10197788
0.54773000
-0.19173498  0.74170610  1.10240139  1.32562483

How can t1 and t2 be combined in an object with dim(object)=c(2,4,10)?
Thank you and wishing you a great day!
Georg.
*****************************
Georg B. Ehret
Johns Hopkins
Baltimore, USA

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list