.BG
.FN diag
.TL
Diagonal Matrices
.CS
diag(x, nrow, ncol)
.AG x
matrix or vector.
Missing values (`NA's) are allowed.
.AG nrow
optional number of rows of output matrix.
.AG ncol
optional number of columns of output matrix.
.RT
if `x' is a matrix,
the vector of diagonal elements of `x';
otherwise, a matrix with `x' on its diagonal and zeroes
elsewhere.
If `x' is a vector of length 1 and both `nrow' and `ncol'
are missing, the value is an `x' by `x' identity matrix.
By default, the
matrix is square with zeros off the diagonal, but it can be
made rectangular by specifying `nrow' and `ncol'.
.EX
diag(xmat)    # extract diagonal

diag(diag(xmat))   # square matrix with diagonal of xmat

diag(5)   # 5 by 5 identity matrix

diag(x,nrow=length(x))  # put x on the diagonal of a matrix
  # works even if length(x) is 1

x[ row(x)==col(x) ] <- diag(y)  # put diagonal of y
   # into diagonal of x
.KW array
.KW algebra
.WR
