[R] rq matrix decomposition

Kasper Kristensen kkr at difres.dk
Tue Jun 5 13:08:07 CEST 2007


I guess you could achieve the rq-decompostion like this:

## Transpose and permute
pt <- function(A){n <- nrow(A);t(A)[n:1,n:1]}

## pt(A)=QR  ==>  A=pt(R)pt(Q)
rq <- function(A){
  qr <- qr(pt(A))
  list(Q=pt(qr.Q(qr)),R=pt(qr.R(qr)))
}

## Test it
A <- matrix(rnorm(25),5)
Q <- rq(A)$Q
R <- rq(A)$R
range(R%*%Q-A)

Best regards
Kasper Kristensen



More information about the R-help mailing list