##------------- example of pivoting -- from base' qraux.Rd -------------
X <- Matrix(cbind(int = 1,
b1=rep(1:0, each=3), b2=rep(0:1, each=3),
c1=rep(c(1,0,0), 2), c2=rep(c(0,1,0), 2), c3=rep(c(0,0,1),2)),
sparse=TRUE)
X # is singular, columns "b2" and "c3" are "extra"
(qx <- qr(X))
# both @p and @q are non-trivial permutations
drop0(R. <- qr.R(qx), tol=1e-15) # columns are int b1 c1 c2 b2 c3
Q. <- qr.Q(qx)
qI <- sort.list(qx@q) # the inverse 'q' permutation
(X. <- drop0(Q. %*% R.[, qI], tol=1e-15))## just = X
stopifnot(all(X - X.) < 8*.Machine$double.eps,
## qR(.) returns R already "back permuted" (as with qI):
identical(R.[, qI], qrR(qx)) )
Run the code above in your browser using DataLab