[R] Matrix of Matrices?

Alaios alaios at yahoo.com
Fri Feb 11 15:17:16 CET 2011


Thanks that did the work. Once I have that list what is the easiest way to export the structure as well as the contents (numbers) into a file.

The purpose is to share that file with a colleague and ask him to load that variable with its contents and structure.

Best Regards
Alex

--- On Fri, 2/11/11, Petr Savicky <savicky at praha1.ff.cuni.cz> wrote:

> From: Petr Savicky <savicky at praha1.ff.cuni.cz>
> Subject: Re: [R] Matrix of Matrices?
> To: r-help at r-project.org
> Date: Friday, February 11, 2011, 12:22 PM
> On Thu, Feb 10, 2011 at 11:54:50PM
> -0800, Alaios wrote:
> > Dear all I have a few matrices that I would like to
> store alltogether under a bigger object.
> > My matrixes with the same name were calculated inside
> a loop like
> > 
> > for (few times){
> > 
> >    estimatedsr<- this is my matrix
> >    savematrixasimagefile();
> >    
> > 
> > }
> > 
> > which means that I was losing all that instances.
> > What can I do to keep all these matrices? ( I do not
> know in advance their number, so I can not preallocate
> space). 
> > How can I store them and adress them back again?
> > 
> > I would like to thank you in advance in your help
> 
> Hello.
> 
> A possible approach is to use list (see ?list).
> 
>   lst <- list()
>   lst[[1]] <- rbind(c(1, 2), c(1, 2))
>   lst[[2]] <- rbind(c(3, 3), c(4, 4))
>   lst
> 
>   [[1]]
>        [,1] [,2]
>   [1,]    1    2
>   [2,]    1    2
>   
>   [[2]]
>        [,1] [,2]
>   [1,]    3    3
>   [2,]    4    4
> 
> If you know in advance an upper bound on the number of
> matrices,
> then it is possible to use an array (see ?array). For
> example
> storing two matrices 2 x 2 may be done as follows
> 
>   a <- array(dim=c(2, 2, 2))
>   a[,,1] <- rbind(c(1, 2), c(1, 2))
>   a[,,2] <- rbind(c(3, 3), c(4, 4))
>   a
> 
>   , , 1
>   
>        [,1] [,2]
>   [1,]    1    2
>   [2,]    1    2
>   
>   , , 2
>   
>        [,1] [,2]
>   [1,]    3    3
>   [2,]    4    4
> 
> Hope this helps.
> 
> Petr Savicky.
> 
> ______________________________________________
> 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.
> 


 
____________________________________________________________________________________
Don't get soaked.  Take a quick peek at the forecast
with
uts/#loc_weather



More information about the R-help mailing list