I suggest adding a 'pivot' argument to qr.R, to obtain columns in the
same order as the original x, so that
  a <- qr(x)
  qr.Q(a) %*% qr.R(a, pivot=TRUE)
returns x.

--------------------------------------------------
#  File src/library/base/R/qr.R

qr.R <- function(qr, complete = FALSE, pivot = FALSE)
{
  # Args:
  #   qr: a QR decomposition, produced by qr()
  #   complete: logical, if TRUE then return all columns
  #   pivot: logical, if TRUE then columns of the result are permuted to
  #        be in the same order as the original x.
  if (!is.qr(qr))
    stop("argument is not a QR decomposition")
  R <- qr$qr
  if (!complete)
    R <- R[seq.int(min(dim(R))), , drop = FALSE]
  R[row(R) > col(R)] <- 0
  if(pivot)
    R <- R[, order(qr$pivot)]
  R
}


--------------------------------------------------
% File src/library/base/man/qraux.Rd

qr.R(qr, complete = FALSE, pivot = FALSE)

\item{pivot}{logical expression of length 1.  If \code{TRUE},
  then columns of the result are permuted to be in the same order
  as the original \code{x}.}

zapsmall(qr.R(a))               # columns are int b1 c1 c2 b2 c3
zapsmall(qr.R(a, pivot = TRUE)) # columns are int b1 b2 c1 c2 c3

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to