From Jonathan Rougier <J.C.Rougier@durham.ac.uk>  Wed Sep  1 14:14:18 1999
From: Jonathan Rougier <J.C.Rougier@durham.ac.uk> (Jonathan Rougier)
Date: Wed, 1 Sep 1999 14:14:18 +0100 (BST)
Subject: diag()
Message-ID: <Pine.GSO.3.96.990901140456.19209D-100000@laplace>

Hi Martin,

Just to follow my previous suggestion to modify diag(), the code I
suggested is vulnerable to matrices with dimnames(x) <- list(NULL, NULL),
which does occasionally happen (it has just happened to me!), so the
following would be better ...

"diag" <-
function (x = 1, nrow, ncol = n) 
{
    if (is.matrix(x) && nargs() == 1) {
        md <- min(dim(x))
        y <- c(x)[1 + 0:(md - 1) * (dim(x)[1] + 1)]
        nms <- dimnames(x)
        if (is.list(nms) && !any(sapply(nms, is.null)) &&
          all(nms[[1]][1:md] == nms[[2]][1:md])) 
            names(y) <- nms[[1]][1:md]
        return(y)
    }

... the rest as in the original function.  Cheers, Jonathan.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE

"[B]egin upon the precept ... that the things we see are to be 
 weighed in the scale with what we know"  (Meredith, 1879, The Egoist)


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


diag()
Jonathan Rougier