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

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Nov 1 10:30:13 CET 2007


As the posting guide says:

  If you are using an old version of R and think it does not work properly.
   upgrade to the latest version and try that, before posting.

This works in current R and current Matrix (0.999375-3)

It also says

   If the question relates to a contributed package , e.g., one downloaded
   from CRAN, try contacting the package maintainer first. You can also use
   find("functionname") and packageDescription("packagename") to find this
   information. Only send such questions to R-help or R-devel if you get no
   reply or need further assistance. This applies to both requests for help
   and to bug reports.


On Thu, 1 Nov 2007, Gerrit Eichner wrote:

> 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
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list