# How could $E(X\mid Y)$ be a function of $Y$?

When I was solving $$\operatorname{Cov}(X,E(X\mid Y)) = \operatorname{var}(E(X\mid Y))$$, I notice that $$E(X\mid Y)$$ was treated as a function of $$Y$$. My thinking is $$E(X\mid Y)$$ is taking values of $$\operatorname{Range}(Y)$$ and for each value of $$Y$$, it maps to the expectation of $$X$$. Is this correct?

An easy way to clarify : if $$f(y)=\mathbb E[X\mid Y=y]$$, then $$\mathbb E[X\mid Y]=f(Y)$$.

Let a discrete r.v. $$X$$ have values $$x\in \{ -6,-3,7,14\}$$, and $$P(X=x)=(0.1,0.2,0.3,0.4)$$ respectively. Define a r.v. $$Y$$ s.t. $$Y=0$$ if $$X \le0$$, and $$Y=1$$ if $$X>0$$.
Then $$E(X|Y)$$ assumes different values for different values of $$Y$$ as follows.
$$Y=0:$$ $$E(X|Y=0)=\sum_{x\in\{-6,-3\}} xP(X=x|Y=0)=-6\times1/3-3\times2/3=-4$$
$$Y=1$$: $$E(X|Y=1)=\sum_{x\in\{7,14\}} xP(X=x|Y=1)=7\times3/7+14\times4/7=11$$
Obviously, $$E(X|Y)$$ is a function of $$Y$$. Also, note how the conditional probabilities, $$P(X=x|X=y)$$, change from the original marginal probabilities, $$P(X)$$, for different $$y$$.