Re: diag()

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: diag()
From: Martin Maechler (maechler@stat.math.ethz.ch)
Date: Thu 02 Sep 1999 - 06:13:09 EST


Message-Id: <199909012013.WAA14572@sophie.ethz.ch>

>>>>> On Wed, 1 Sep 1999 14:14:18 +0100 (BST), Jonathan Rougier <J.C.Rougier@durham.ac.uk> said:

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

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

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

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

Your proposal has been (slightly improved) and commited for 0.64.1
(or tomorrow's snapshot of R-release).

NEWS has
     
    o diag(x) now keeps names when appropriate and barfs when x is an array.

Thank you very much. Martin

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


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:08 EST