Re: [R] matrix size

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Mon 01 Jan 2007 - 23:18:45 GMT

>>>>> "GArmelini" == Armelini, Guillermo <DOCGArmelini@iese.edu>
>>>>> on Mon, 1 Jan 2007 23:43:31 +0100 writes:

    GArmelini> Hello everyone Could anybody tell me how to set     GArmelini> the following matrix?  

    GArmelini> n2<-matrix(nrow=10185,ncol=10185,seq(0,0,length=103734225))  

    GArmelini> R answer was Error: cannot allocate vector of     GArmelini> size 810423 Kb

of course.  

    GArmelini> Are there any solution? I tried to increase the     GArmelini> memory size but it didn't work G

You might consider using *sparse* matrices such as available by R's "Matrix" package.

 install.packages("Matrix") # once only  library(Matrix) # every time you use it  n2 <- Matrix(0, nrow=10185, ncol=10185)

will produce a sparse Matrix (of class "dsCMatrix") that does not need a lot of memory.

If you want to do anything reasonable, with 'n2' I assume you'll want to add some non-zero entries.

To do that (and similary things) a bit more efficiently in the current implementations of "Matrix",
I'd recommend to work with a "TsparseMatrix" (instead of the `default' Csparse*), i.e. a sparse matrix representation working with so called triplets, e.g.

m2 <- as(n2, "TsparseMatrix")
m2[1,3] <- 10
m2[2, 1:10] <- 0:9

m2[1:10, 1:20]

etc,..
BTW: Such sub-assignments should now work, but some or still slow. Till now the main emphasis for such matrices was general good organization and speed in matrix operations rather than "index operations".

I'm quite interested to hear what you want to do with your matrix. Use R-help if you think it could be of general interest, or reply privately if you prefer.

Regards,
Martin Maechler, ETH Zurich



R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Tue Jan 02 10:24:26 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 01 Jan 2007 - 23:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.