## generate sample data
set.seed(1234)
n <- 12
p <- 5
X <- matrix(rnorm(n * p), n, p)
## get the full QR decomposition with pivot
qr_res <- fastQR::qr_fast(X = X,
tol = sqrt(.Machine$double.eps),
pivot = TRUE)
## get the full Q matrix
Q1 <- qr_Q(qr_res$qr, qr_res$qraux, complete = TRUE)
## check the Q matrix (orthogonality)
max(abs(crossprod(Q1)-diag(1, n)))
## get the reduced Q matrix
Q2 <- qr_Q(qr_res$qr, qr_res$qraux, qr_res$rank, complete = FALSE)
## check the Q matrix (orthogonality)
max(abs(crossprod(Q2)-diag(1, p)))
Run the code above in your browser using DataLab