Conditional expectation $E(X | X<Y)$ when $X$ and $Y$ are independent I'm stuck calculating the following expectation:


  Given a (discrete) RV $X$ with $P(X=0)=P(X=1)=P(X=2)=1/3$ and $Y \sim \text{Unif}(0,2)$ what is $E(X | X&lt;Y)$?


Now what I did was conditioning on $Y$, i.e.
\begin{align}
E(X | X&lt;Y)
&amp;=\int_0^2\frac{1}{2}E(X | X&lt;y)dy \\
&amp;=\int_0^1\frac{1}{2}E(X | X&lt;y)dy+\int_1^2\frac{1}{2}E(X | X&lt;y)dy \\
&amp;=\frac{1}{2}\cdot 0 + \frac{1}{2} \cdot 1=\frac{1}{2}.
\end{align}
To confirm this I simulated the situation with R. I simulated an instance of $X$ and $Y$ 10,000 times and if $X &lt; Y$ I remembered $X$. However the mean of this list was $\frac{1}{3}$ and not $\frac{1}{2}$ as expected.

Can someone tell me what I did wrong? Thanks!
The answer is $1/3$.  Given that $X&lt;Y$, there are three possible situations, depending on the value of $X$, but they're not all equally likely:
$X=0, Y&gt;0$ (probability $2/3$); $X=1,Y&gt;1$ (probability $1/3$), and $X=2,Y&gt;2$ (probability $0$).  Thus $E[X | X&lt;Y] = 0(2/3) + 1(1/3) + 2(0) = 1/3$.
Another way to look at the problem (and to check your result)  is to approach from this angle: $$E(X|X&lt;Y)=\sum_{i=0}^2 i \cdot P(X=i \ | \ Y&gt;X)$$
and $$P(Y&gt;X) = \sum_{i=0}^2 P(Y &gt; X \ | \ X=i) \cdot P(X=i) $$

I took advantage of this approach and determined that the expected value is in fact $\frac{1}{3}$