Re: [R] Warning while subsetting using Matrix package

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Thu 06 Jul 2006 - 17:32:31 EST

>>>>> "JohnT" == Thaden, John J <ThadenJohnJ@uams.edu>
>>>>> on Thu, 6 Jul 2006 00:02:10 -0500 writes:

  JohnT> > # ...I had previously created a sparse matrix in triplet form:
  JohnT> > str(x)
  JohnT> Formal class 'dgTMatrix' [package "Matrix"] with 6 slots
  JohnT>   ..@ i       : int [1:923636] 1 2 3 4 5 6 7 8 9 10 ...
  JohnT>   ..@ j       : int [1:923636] 1 1 1 1 1 1 1 1 1 1 ...
  JohnT>   ..@ Dim     : int [1:2] 600 4482
  JohnT>   ..@ Dimnames:List of 2
  JohnT>   .. ..$ : chr [1:601] "50" "51" "52" "53" ...
  JohnT>   .. ..$ : chr [1:4482] "1" "2" "3" "4" ...
  JohnT>   ..@ x       : num [1:923636] 50.2 51.2 52.2 53.2 54.2 ...
  JohnT>   ..@ factors : list()
  JohnT> >
  JohnT> > # While subsetting x, I was surprised to get this warning: 
  JohnT> > y<-x[1:300,]
  JohnT> Warning message:
  JohnT> number of items to replace is not a multiple of replacement length

and later

    JohnT> Sorry, I omitted background information:
    JohnT> R version: 2.3.0
    JohnT> OS: Windows XP
    JohnT> CPU:  Pentium III, 
    JohnT> RAM:  768 MB

You omitted the most pertinent information: The version of 'Matrix' you are using.
The latest released version of Matrix does *not* show the behavior you mentioned.
{So I have now spent 20 minutes just because you did not update 'Matrix'..}

    JohnT> Also, what command-line memory settings might prevent R from crashing
    JohnT> while using the Matrix package to convert my 600 X 4482 dgTMatrix to the
    JohnT> dgCMatrix class or to an expanded Matrix, via the as() function? I can
    JohnT> do this with half of the matrix, 300 x 4482.

It's hard to believe that you get a "crash" when coercing to 'dgC' -- but of course this really depends how much memory you have already goggled up by other large objects in your R workspace, or by other applications running at the same time in Windows. Coercing to a full matrix will of course require 8 * 601 * 4482 = 21549456 extra bytes just for the numbers. That's only 21.5 Megabytes, so I wonder..

I have never seen R crashes from using 'Matrix', but then I work with an operating system, not with M$ Windows. Maybe you meant you got an error message "... memory allocation .."?

    JohnT> Thanks,
    JohnT> John T



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 Received on Thu Jul 06 17:36:45 2006

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 Sun 09 Jul 2006 - 06:16:22 EST.

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