Let $A$ be an $n\times m$ matrix with rank $r$. Then $A$ can be written as
$$A=QR$$
where $Q$ is $n\times r$ with orthonormal columns and $R$ is $r\times m$ upper triangular.
Proof. Apply the Gram–Schmidt process to the columns of $A$, discarding any column which can written as a linear combination of the previous columns. This produces orthonormal vectors $q_1,\dots,q_r$. By induction we see that the $j$th column of $A$ lies in the span of $q_1,\dots,q_{\min{(j,r)}}$ for $j=1,\dots, n$. This means that $A=QR$ with $Q,R$ having the desired properties.
Now the answer given here suggests that the decomposition above is unique if we require positive leading entries in every row of $R$.
How can one prove this?
Thanks a lot for your help.
For the $n\times n$ non-singular case, you can rely on uniqueness of the Cholesky decomposition. If $A=QR$ then $A^\top A = R^\top R$ is positive definite. I believe you can use a similar argument in your case.