Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner
Please supply some test data and the expected answer since its not clear what is desired here. On 4/5/06, Werner Wernersen <pensterfuzzer at yahoo.de> wrote:> Hi, > > this is probably the easiest thing to do but I manage > not finding the answer: > I have a list with matrices of exact same format and > headers. Now I would like to transform the list into > an normal array. What is the proper way to do this? > as.array changes the entire format and right now I > only found the method of creating a new array, going > through the entire list and copy the matrix in each > list element to the new array. > > Thanks a million for your help! > Werner > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
probably you're looking for either
do.call("rbind", lis)
or
do.call("cbind", lis)
where 'lis' is your list.
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Werner Wernersen" <pensterfuzzer at yahoo.de>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, April 05, 2006 2:55 PM
Subject: [R] List to Array
> Hi,
>
> this is probably the easiest thing to do but I manage
> not finding the answer:
> I have a list with matrices of exact same format and
> headers. Now I would like to transform the list into
> an normal array. What is the proper way to do this?
> as.array changes the entire format and right now I
> only found the method of creating a new array, going
> through the entire list and copy the matrix in each
> list element to the new array.
>
> Thanks a million for your help!
> Werner
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Werner Wernersen <pensterfuzzer <at> yahoo.de> writes:> > Hi, > > this is probably the easiest thing to do but I manage > not finding the answer: > I have a list with matrices of exact same format and > headers. Now I would like to transform the list into > an normal array. What is the proper way to do this?I think if you really mean array (i.e. an n-dimensional table with n>2) then something like the following will do it: ## create an example list of matrices z <- replicate(5,matrix(runif(9),nrow=3),simplify=FALSE) library(abind) do.call("abind",c(z,list(along=3))) Ben Bolker
On 4/5/06, Ben Bolker <bolker at ufl.edu> wrote:> Werner Wernersen <pensterfuzzer <at> yahoo.de> writes: > > > > > Hi, > > > > this is probably the easiest thing to do but I manage > > not finding the answer: > > I have a list with matrices of exact same format and > > headers. Now I would like to transform the list into > > an normal array. What is the proper way to do this? > > I think if you really mean array (i.e. an n-dimensional > table with n>2) then something like the following will do it: > > ## create an example list of matrices > z <- replicate(5,matrix(runif(9),nrow=3),simplify=FALSE) > library(abind) > do.call("abind",c(z,list(along=3)))Note that if that is what he is looking for then abind(z, along = 3) will do it too.
Oh yes, I should give an example:
m <- matrix(1:6,nrow=3)
L <- list(m,m)
Output of L:
[[1]]
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
[[2]]
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
I would like to transform L to and array looking like
this:
, , 1
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
, , 2
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> Please supply some test data and the expected answer
> since its not clear what is desired here.
>
> On 4/5/06, Werner Wernersen <pensterfuzzer at yahoo.de>
> wrote:
> > Hi,
> >
> > this is probably the easiest thing to do but I
> manage
> > not finding the answer:
> > I have a list with matrices of exact same format
> and
> > headers. Now I would like to transform the list
> into
> > an normal array. What is the proper way to do
> this?
> > as.array changes the entire format and right now I
> > only found the method of creating a new array,
> going
> > through the entire list and copy the matrix in
> each
> > list element to the new array.
> >
> > Thanks a million for your help!
> > Werner
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >
>