how to derive the steps of principal component analysis? I'm trying to understand the theoretical reasoning behind the method, but I can't understand a particular step in the middle of this page.

"The constraint on the numbers in $v_1$ is that the sum of the squares of the coefficients equals $1$. Expressed mathematically, we wish to maximize
$$\frac1N\sum_{i=1}^NY_{1i}^2$$

where
$$y_{1i}=v_1'z_i,$$

and $$v_1'v_1=1$$ 

(this is called "normalizing" $v_1$).
Computation of first principal component from $R$ and $v_1$. Substituting the middle equation in the first yields

$$\frac1N\sum_{i=1}^NY_{1i}^2=v_1'Rv_1."$$

I don't understand how $R$ suddenly appeared in this equation. The right hand side "$v_1' R v_1$" seems to have appeared out of nowhere.

Please help
\begin{align}
\frac1N\sum_{i=1}^N Y_{1i}^2 &amp;= \frac1N\sum_{i=1}^N (v_1'z_i)(z_i'v_1)\\
&amp;=v_1'\left(\frac1N \sum_{i=1}^N z_iz_i' \right) v_1 \\
&amp;= v_1'Rv_1
\end{align}

where $R=\frac1N \sum_{i=1}^N z_iz_i'.$