[R] incorrect result for Matrix() %*% Diagonal()

Gerald Jansen gerald.jansen at newpage.ca
Thu Oct 19 21:05:15 CEST 2006


I'm exploring pedigree() in lme4 and found some strange results trying
to multiply a dtCMatrix by a diag() matrix using %*%. Studying the 
Matrix documentation, I stumbled upon the following error in the 
example on the ddiMatrix-class {Matrix} help page. I wonder if my
problem could be related to this.

> matrix(cbind(1, 2:4),3,2) %*% diag(c(10,1)) # OK
     [,1] [,2]
[1,]   10    2
[2,]   10    3
[3,]   10    4

> Matrix(cbind(1, 2:4)) %*% Diagonal(x=c(10,1)) # KO
3 x 2 Matrix of class "dgeMatrix"
     [,1] [,2]
[1,]   10    2
[2,]    1   30
[3,]   10    4

===========================================
> sessionInfo()
R version 2.4.0 (2006-10-03) 
x86_64-pc-linux-gnu 

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

other attached packages:
      lme4     Matrix    lattice 
"0.9975-4" "0.9975-3"   "0.14-9" 
==============================================

Thanks in advance
Gerald Jansen



More information about the R-help mailing list