$m$ minimizes $E(|X-a|)$ over $a\in R$ if and only if $m$ is a median for $X$. I'm trying to show that $E(|X-a|)$ attains its minimum value if and only if $a=m$ where $m$ is the median. I know this particular problem has been discussed before, but I want to prove it in a specific way which I could not find elsewhere.
My attempt:
Assume $m\neq a$ and suppose $m<a$
If $X<m<a$, then $|X-a|-|X-m|=(a-X)-(m-X)=a-m$
If $m<X<a$, then $|X-a|-|X-m|=(a-X)-(X-m)=a+m-2X$
If $m<a<X$ ,then $|X-a|-|X-m|=(X-a)-(X-m)=m-a$
Now, I want to deductively show that $E(|X-a|)-E(|X-m|)>0$ However, I'm not sure how to go about solving this. Can anyone please chime in?
And clearly, once, I solve this, I can symmetrically solve the case where $m>a$ the same way.
 A: Using (a slight modification of) the above characterisation, show that for $m <a,$ $$\mathbb{E}[|X-a| - |X-m|] = (a-m) ( P(X \le m) - P(X > a) ) + \mathbb{E}[(a + m - 2X)\mathbf{1}\{ X \in (m, a] \}].$$ You can further lower bound this by $$ (a-m) ( P(X \le m) - P(X > m) ) = (a-m) (2P(X \le m) - 1)$$ by noticing that for $X \in (m,a], a +m - 2X \ge -(a-m)$. 
Now, $a - m > 0$, and by the definition of the median, $P(X \le m) \ge 1/2.$ Note that you cannot in general get a strict inequality - this is because the median need not be unique. To get this needs more work.

Since you wanted the first equality explained (this is just the argument angryavian poses, carried out in detail).
first, I'll edit your characterisation a little by making the first case be $X\le m$ and the second be $m < X \le a$. This clearly doesn't alter anything.
Now, for succinctness, let $f(X) := |X-a| - |X-m|.$ \begin{align}
\mathbb{E}[f(X)] &= \mathbb{E}[f(X) \mathbf{1}\{X \le m\}] + \mathbb{E}[f(X) \mathbf{1}\{m < X \le a\}] + \mathbb{E}[f(X) \mathbf{1}\{X > a\}]  
\end{align}
Now, for $X \le m,$ $f(X) = a-m$. Similarly in other domains. Using htis, we have $$ \mathbb{E}[f(X)] = (a-m) \mathbb{E}[\mathbf{1}\{X \le m\}] + \mathbb{E}[f(X) \mathbf{1}\{m < X \le a\}] + \mathbb{E}[ (m-a) \mathbf{1}\{X > a\}]. $$
Now just note that $a-m$ is a constant, and that $\mathbb{E}[\mathbf{1}\{X \in E\}] = P(X \in E)$.
