Detailed description |
`Matrix/R/diagMatrix.R` contains:
```
.ddi2mat <- function(from)
base::diag(if(from@diag == "U") as1(from@x) else from@x, nrow = from@Dim[1])
setAs("ddiMatrix", "matrix", .ddi2mat)
```
`.ddi2mat(from)` does not use `from@Dimnames`, so `as(<ddiMatrix>, "matrix")` loses `[dD]imnames`.
```
> library("Matrix")
> x <- Diagonal(n = 5, x = 1:5)
> dimnames(x)[] <- list(letters[1:5])
> x
5 x 5 diagonal matrix of class "ddiMatrix"
a b c d e
a 1 . . . .
b . 2 . . .
c . . 3 . .
d . . . 4 .
e . . . . 5
> as(x, "matrix")
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 0
[2,] 0 2 0 0 0
[3,] 0 0 3 0 0
[4,] 0 0 0 4 0
[5,] 0 0 0 0 5
```
A patch:
```
.ddi2mat <- function(from) {
res <- base::diag(if(from@diag == "U") as1(from@x) else from@x, nrow = from@Dim[1])
dimnames(res) <- from@Dimnames
res
}
``` |
|