[R] matrices dimensions limitation

Marc Schwartz marc_schwartz at comcast.net
Thu Mar 1 19:11:39 CET 2007


On Thu, 2007-03-01 at 18:20 +0100, Bruno C. wrote:
> Hello,
> I have several questions around matrices size limitation:
>      can i create a matrix with 700000 rows?
>      does it depends on the number of columns?
>      if so can Is there a way to ask to R, given the number of
> columns, the max number of rows I can have?
> 
> I need in fact to do regression prediction on a huge matrix
> (700000x1000)ca. ... 
> I will probably have to decompose it on several matrices, and I would
> do that in an intelligent way so that if my observation matrix size
> change I do not need to rewrite my code...
> 
> Thanx in advance

See ?"Memory-limits":

"There are also limits on individual objects. On all versions of R, the
maximum length (number of elements) of a vector is 2^31 - 1 ~ 2*10^9, as
lengths are stored as signed integers. In addition, the storage space
cannot exceed the address limit, and if you try to exceed that limit,
the error message begins cannot allocate vector of length. The number of
characters in a character string is in theory only limited by the
address space."


Keep in mind that a matrix is a vector with a 'dim' attribute.

I am running Linux on a system with 2Gb of RAM:

> MAT <- matrix(rnorm(700000 * 1000), ncol = 1000)
Error in rnorm(7e+05 * 1000) : cannot allocate vector of length 70000000

So hopefully, you have more RAM that I do...  :-)

HTH,

Marc Schwartz



More information about the R-help mailing list