Really confused why the QR output using RcppArmadillo is different than QR output from R; Armadillo documentation doesnt give a clear answer either. Essentially when I give R a matrix Y that is n * q (say 1000 X 20 ) , I get back Q which is 1000 X 20 and R 20 X 1000. This is what I need. But when I use the QR solver in Armadillo, it throws me back Q 1000 X 1000 and R 1000 X 20. Can I call R's qr function instead? I need Q to have dimension n x q, not q x q. Code below is what I am using(its a part of a bigger function).
If someone can suggest how to do it in RcppEigen, that'd be helpful too.
library(inline)
library(RcppArmadillo)
src <- '
Rcpp::NumericMatrix Xr(Xs);
int q = Rcpp::as<int>(ys);
int n = Xr.nrow(), k = Xr.ncol();
arma::mat X(Xr.begin(), n, k, false);
arma::mat G, Y, B;
G = arma::randn(n,q);
Y = X*G;
arma::mat Q, R;
arma::qr(Q,R,Y);
return Rcpp::List::create(Rcpp::Named("Q")=Q,Rcpp::Named("R")=R,Rcpp::Named("Y")=Y);'
rsvd <- cxxfunction(signature(Xs="numeric", ys="integer"), body=src, plugin="RcppArmadillo")