[R] Matrix package problem: dsyMatrix %*% vector gives error

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Thu Nov 1 10:00:48 CET 2007


Dear UseRs,

here is an example scenario presenting my problem:

Multiplying a dsyMatrix with a numeric vector results in an error 
(unfortunately in German due to my locale):

> (M1 <- Matrix( c( 1, 2, 2, 2, 1, 2, 2, 2, 1), nrow = 3))
3 x 3 Matrix of class "dsyMatrix"
      [,1] [,2] [,3]
[1,]    1    2    2
[2,]    2    1    2
[3,]    2    2    1

> M1 %*% 1:3
Fehler in x %*% as.matrix(y) : kann keinen Slot ("Dim") von einem Objekt 
vom Typ "integer" bekommen


This does not happen when the multiplication is done with a dgeMatrix, for 
example:

> (M2 <- Matrix( 1:9, nrow = 3))
3 x 3 Matrix of class "dgeMatrix"
      [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
Warning message:
integer matrices not yet implemented in 'Matrix'; using 'double' ones' in: 
Matrix(1:9, nrow = 3)

> M2 %*% 1:3
3 x 1 Matrix of class "dgeMatrix"
      [,1]
[1,]   30
[2,]   36
[3,]   42


(The warning message seems not important; the problem occurs also with 
non-integer entries.)


However, the problem can be avoided if the dsyMatrix is converted into a 
"normal" matrix beforehand (so the problem is not really a serious one):

> as.matrix( M1) %*% 1:3
      [,1]
[1,]   11
[2,]   10
[3,]    9


However, does one have to use as.matrix()? (I could not find anything 
related despite reading the documentations and browsing the archives).

Thanks for any hint.

  Best regards  --  Gerrit


PS: Here is my session info:

> sessionInfo()
R version 2.5.1 (2007-06-27)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;
LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;
LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
[7] "base"

other attached packages:
       Matrix      lattice
"0.999375-1"    "0.15-11"

---------------------------------------------------------------------
AR Dr. Gerrit Eichner                          Mathematical Institute
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32029               http://www.math.uni-giessen.de



More information about the R-help mailing list