TITLE: Expected Value of a Binomial distribution?
QUESTION [42 upvotes]: If $\mathrm P(X=k)=\binom nkp^k(1-p)^{n-k}$ for a binomial distribution, then from the definition of the expected value
$$\mathrm E(X) = \sum^n_{k=0}k\mathrm P(X=k)=\sum^n_{k=0}k\binom nkp^k(1-p)^{n-k}$$ but the expected value of a Binomal distribution is $np$, 
so how is 

$$\sum^n_{k=0}k\binom nkp^k(1-p)^{n-k}=np$$

REPLY [3 votes]: Since there are already great direct answers there, let me show you an alternative approach via differential calculus:
\begin{align}
\sum_i^N i \binom{N}{i} a^{i} b^{N-i} &= a \sum_i^N i \binom{N}{i} a^{i-1} b^{N-i} \\ 
&= a \frac{d}{da}\sum_i^N \binom{N}{i} a^{i} b^{N-i} \\
&= a \frac{d}{da}(a+b)^N \\
&= a N(a+b)^{N-1} \\
\end{align}
Now substitute $a = p$ and $b = 1-p$ will give you the expectation. $\blacksquare$