I'm trying to follow the solution of this exercise: link.
It says: Let $X$ and $Y$ be two jointly continuous random variables with joint PDF
$ \begin{equation} \nonumber f_{XY}(x,y) = \left\{ \begin{array}{l l} 2 & \quad y+x \leq 1, x>0, y>0 \\ & \quad \\ 0 & \quad \text{otherwise} \end{array} \right. \end{equation} $
To find $E[X]$, I would expect it to be:
$E[X] = \int_{0}^{1-y}{2dx}$
And have $E[X]$ be a function of $y$.
But the solution actualy integrates the function over $y$ to get a function of $x$ and then integrate again to get $E[X]$:
$ \begin{align}%\label{} \nonumber f_X(x)&=\int_{-\infty}^{\infty} f_{XY}(x,y)dy \\ \nonumber &=\int_{0}^{1-x}2dy\\ \nonumber &=2(1-x). \end{align} $
$ \begin{align}%\label{} \nonumber E[X]&=\int_{0}^{1}2x(1-x)dx\\ \nonumber &=\frac{1}{3}=EY, \end{align} $
What is the idea behind integrating a bivariate $PDF_{x,y}$ before integrating to calculate the $E[X]$.