# Confusion with the QR decomposition

I have some trouble to understand this:

According to the factorization QR, Given a matrix $$A\in\mathbb{R}^{n\times p}$$, with $$rank=min(n,p)$$, there exists an orthogonal matrix $$Q\in\mathbb{R}^{n\times n}$$ and an upper triangular matrix $$R\in\mathbb{R}^{n\times p}$$ such that

$$A=QR$$ The problem is that when I apply the factorization QR to solve the least squares problem. I suppose that $$n>p$$, then A is full column rank.

But $$Q=[q_1,q_2,...,q_p]\in\mathbb{R}^{n\times p}$$ and $$R\in\mathbb{R}^{p\times p}$$. In this case $$Q^TQ=I_p$$, however according to several definitions an orthongonal matrix is an square matrix. Then this is not a factorization QR.

Another example is provided here: http://www.seas.ucla.edu/~vandenbe/133A/lectures/ls.pdf in the last slide, the matrix Q found, is not orthogonal since is not square.

moreover, according to the definition orthogonal matrix is a matrix $$A$$ such that $$A^TA=AA^T=I$$. But in the example given in the document attached that property does not hold.