diag() losing dimnames

Paul Gilbert pgilbert@bank-banque-canada.ca
Wed, 9 Sep 1998 10:46:54 -0400


Using diag() to extract the diagonal of a matrix loses all but the first dimname
(R 0.62.3). The problem seems to be in [ ]:
>
> x <- matrix(1:9,3,3)
> dimnames(x) <- list(c("a", "b", "c"), c("a", "b", "c"))
> x
  a b c
a 1 4 7
b 2 5 8
c 3 6 9
> diag(x)
 a NA NA
 1  5  9
> x[c(1,5,9)]
 a NA NA
 1  5  9
>

Paul Gilbert

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._