Dear contributors I have tried this experiment: x<-c() for (i in 1:12){ x[i]<-list(cbind(x1[i],x2[i])) #this is a list of 12 couples of time series I am using to perform a test } # that compares them 2 by 2 # ################# #trace statistic test<-data.frame() cval<-array( , dim=c(2,3,12)) for (i in 2:12){ for (k in 1:2){ for (j in 1:3){ result[k,j,i]<- ((ca.jo(data.frame(x[i]),ecdet="none",type="trace", spec="longrun",K=2))@cval[k,j]) }}} I have a problem in collecting the results of a test. The function ca.jo creates an object with various attributes, one of which is the "cval" that i can access through @cval. The attribute cval is an object of dimension 2X3. I am running recursively the test with ca.jo for 12 couples of time series, so I have an output of 12 matrices of 2X3 elements and I would like to create an object like an array of dimension (2,3,12) which contains each matrix @cval produced by ca.jo for the 12 subjects that i tested. Can anyone help me with that? I hope my explanation of the problem is clear. Thanks in advance for any help. -- Francesca ---------------------------------- Francesca Pancotto, PhD Università di Modena e Reggio Emilia Viale A. Allegri, 9 40121 Reggio Emilia Office: +39 0522 523264 Web: http://www2.dse.unibo.it/francesca.pancotto/ ---------------------------------- [[alternative HTML version deleted]]
My first thought is to unlist them and stick them in a vector and then to form that vector into an array of the desired shape. Something like this: x <- vector("list",12) for(i in 6*(1:12)){x[[i/6]] <- matrix(i:(i+5), ncol = 2) } print(x) x.out <- array(unlist(x), dim = c(2,3,12)) print(x.out) which I believe is what you want. [If not, I think it will at least get you started] Hope this helps, Michael On Fri, May 25, 2012 at 5:21 AM, Francesca <francesca.pancotto at gmail.com> wrote:> Dear contributors > I have tried this experiment: > > x<-c() > for (i in 1:12){ > x[i]<-list(cbind(x1[i],x2[i])) ?#this is a list of 12 couples of time > series I am using to perform a test > } # that compares them 2 by 2 > # > ################# > #trace statistic > test<-data.frame() > cval<-array( , dim=c(2,3,12)) > for (i in 2:12){ > for (k in 1:2){ > for (j in 1:3){ > result[k,j,i]<- ((ca.jo(data.frame(x[i]),ecdet="none",type="trace", > ? ? ?spec="longrun",K=2))@cval[k,j]) > }}} > > I have a problem in collecting the results of a > test. > The function ca.jo creates an object with various attributes, > one of which is the "cval" that i can access through @cval. > The attribute cval is an object of dimension 2X3. > I am running recursively the test with ca.jo for 12 > couples of time series, so I have an output of 12 matrices of 2X3 > elements and I would like to create an object like an array > of dimension (2,3,12) which contains each matrix @cval > produced by ca.jo for the 12 subjects that i tested. > > Can anyone help me with that? > I hope my explanation of the problem is clear. > Thanks in advance for any help. > > -- > > Francesca > > ---------------------------------- > Francesca Pancotto, PhD > Universit? di Modena e Reggio Emilia > Viale A. Allegri, 9 > 40121 Reggio Emilia > Office: +39 0522 523264 > Web: http://www2.dse.unibo.it/francesca.pancotto/ > ---------------------------------- > > ? ? ? ?[[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. >
?abind ## in R package abind. Very handy for this sort of thing Something like: do.call(abind, yourlist) You can also do it by hand along the lines Michael described: e.g. something like array(unlist(yourlist), dim = c(2,3, 12) ) -- Bert On Fri, May 25, 2012 at 6:16 AM, R. Michael Weylandt <michael.weylandt at gmail.com> wrote:> My first thought is to unlist them and stick them in a vector and then > to form that vector into an array of the desired shape. > > Something like this: > > x <- vector("list",12) > for(i in 6*(1:12)){x[[i/6]] <- matrix(i:(i+5), ncol = 2) } > > print(x) > > x.out <- array(unlist(x), dim = c(2,3,12)) > > print(x.out) > > which I believe is what you want. [If not, I think it will at least > get you started] > > Hope this helps, > > Michael > > On Fri, May 25, 2012 at 5:21 AM, Francesca <francesca.pancotto at gmail.com> wrote: >> Dear contributors >> I have tried this experiment: >> >> x<-c() >> for (i in 1:12){ >> x[i]<-list(cbind(x1[i],x2[i])) ?#this is a list of 12 couples of time >> series I am using to perform a test >> } # that compares them 2 by 2 >> # >> ################# >> #trace statistic >> test<-data.frame() >> cval<-array( , dim=c(2,3,12)) >> for (i in 2:12){ >> for (k in 1:2){ >> for (j in 1:3){ >> result[k,j,i]<- ((ca.jo(data.frame(x[i]),ecdet="none",type="trace", >> ? ? ?spec="longrun",K=2))@cval[k,j]) >> }}} >> >> I have a problem in collecting the results of a >> test. >> The function ca.jo creates an object with various attributes, >> one of which is the "cval" that i can access through @cval. >> The attribute cval is an object of dimension 2X3. >> I am running recursively the test with ca.jo for 12 >> couples of time series, so I have an output of 12 matrices of 2X3 >> elements and I would like to create an object like an array >> of dimension (2,3,12) which contains each matrix @cval >> produced by ca.jo for the 12 subjects that i tested. >> >> Can anyone help me with that? >> I hope my explanation of the problem is clear. >> Thanks in advance for any help. >> >> -- >> >> Francesca >> >> ---------------------------------- >> Francesca Pancotto, PhD >> Universit? di Modena e Reggio Emilia >> Viale A. Allegri, 9 >> 40121 Reggio Emilia >> Office: +39 0522 523264 >> Web: http://www2.dse.unibo.it/francesca.pancotto/ >> ---------------------------------- >> >> ? ? ? ?[[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. >> > > ______________________________________________ > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm