I found the following R code using qr factorization cannot recover the original matrix. I cannot figure out why.
a <- matrix(runif(180),ncol=6)
a[,c(2,4)] <- 0
b <- qr(a)
d <- qr.Q(b) %*% qr.R(b)
then d is different from a in the way that all the zero columns are moved the the right side. It seems that qr factorization does not keep the row space.
When you read the help for
qryou see that R uses a pivoted QR-decomposition.So
gives
Thus you need to apply
pivottoaor the inverse ofpivottodto line the matrices up correctly. Sogives
You can also do
which also results in
TRUE.