[Rd] diag() (PR#555)

Bill Venables venables@acland.qld.cmis.csiro.au
Thu, 25 May 2000 12:25:27 +1000


> Full_Name: David Duffy
> Version: 1.0.1
> OS: Linux
> Submission from: (NULL) (152.98.96.21)
> 
> 
> Documentation for diag() states that "If x is a vector (or a
> 1-d array) then diag(x) returns a diagonal matrix whose diagonal
> is x."
> > m <- matrix(1:4,ncol=1)
> > diag(m)
> [1] 1
> diag(as.vector(m)) gives the advertised performance.
> 
> Fix: Change documentation.

On the contrary I consider this to be the advertized performance.

The array m as defined above is a 2-d array, not a 1-d array, it just
so happens that one of the dimensions has extent 1, but so what?

I would favour retaining the definition

	dimension of array A  =  length(dim(A))

in all cases so that you can rely on it in programming and do not have
to consider even more exception handling.  It's bad enough already
with the drop convention.

If anything I think it requires a little more emphasis on what
constitutes an n-dimensional array and precisely what drop(m) does,
for example.  The above equality is *before* drop, not after, in other
words.

-- 
Bill Venables,      Statistician,     CMIS Environmetrics Project
CSIRO Marine Labs, PO Box 120, Cleveland, Qld,  AUSTRALIA.   4163
Tel: +61 7 3826 7251           Email: Bill.Venables@cmis.csiro.au    
Fax: +61 7 3826 7304      http://www.cmis.csiro.au/bill.venables/



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