Let $X$ be $N(0,1)$. I want to compute $E(|X|)$. This is what I tried:
$$E(|X|)=\frac{1}{\sqrt{2\pi}}\int_{-\infty}^\infty|x|e^{\frac{-x^2}{2}}dx=\frac{2}{\sqrt{2\pi}}\int_{0}^\infty xe^{\frac{-x^2}{2}}dx$$
In order to aim for the gamma function, I do the change of variables $x^2/2=y.$ This results in
$$\frac{2}{\sqrt{2\pi}}\int_{0}^\infty xe^{\frac{-x^2}{2}}dx=\frac{2}{\sqrt{\pi}}\int_{0}^\infty y^{1/2}e^{-y}dy=\frac{2}{\sqrt{\pi}}\Gamma(1/2+1)=\frac{2}{\sqrt{\pi}}\frac{\sqrt \pi}{2}=1$$
This is obviously wrong, but I cannot find my mistake.
Its just a slight mistake within your substitution. In fact by replacing $x^2/2$ with $y$ you have to consider that your differential changes to $xdx=dy$ and not only to $dy$. Therefore the single $x$ is absorbed within the $dy$ instead of remaining as $y^{1/2}$. This finally leads to
$$\int_0^{\infty}e^{-\frac{x^2}2}(xdx)=\int_0^{\infty}e^{-y}dy$$
where the last integral turns out to equal $1$ instead of $\Gamma(1/2+1)$. Therefore your evaluation has to be finished as
$$E(|X|)=\frac{2}{\sqrt{2\pi}}\int_{0}^\infty xe^{\frac{-x^2}{2}}dx=\frac{2}{\sqrt{2\pi}}\int_{0}^\infty e^{-y}dy=\sqrt{\frac{2}{\pi}}$$