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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Gerald Jansen
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

______________________________________________
[hidden email] 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.