I want to do a QR decomposition with the Matrix:::qr() function on a Matrix that I created with B<-as(A, "sparseMatrix"). I know that I can get the R matrix with Matrix:::qr.R(). However, I also need to the Q Matrix. There seems to be no qr.Q() function in the Matrix package. How do I get the Q matrix?
I want to do a QR decomposition with the Matrix:::qr() function on a Matrix
Share
The
Qmatrix is actually stored in theVslot. It seems that the current R Matrix version contains a bug — it just mysteriously adds zero rows into the matrixabefore doing the qr decomposition. I wish the developers could come and explain it. Therefore the following codes help you recover both R and Q:I have tested by randomly set the matrix size and sparsity and they work smoothly. However this is of the style “just make it work without knowing why”, and is posted here only for discussion. Because I have not hacked into the implementation details of the package “Matrix”.