Median of a set of Integer The median of a set containing odd number of integer is the middle element after sorting. What about the case of even number of terms. Some places mention of average of the two middle value, but I heard that precise definition allows any number from the left middle number to the right middle number. For example, {1 2 3 4}, any number between and including 2 and 3 is valid.
 A: It's really a matter of custom-convention-convenience. "If there is an even number of observations, then there is no single middle value; the median is then usually defined to be the mean of the two middle values" (wikipedia). No definite argument (that I'm aware of) dictates that the average is to be prefered, but in many scenarios that seems a reasonable thing to do. Specially if we can assume that the underlying distribution is approximately symmetric around the median.
On one side:  to see that that definition cannot be the last word, consider this example: for a positive random variable $X$ the ("true") median $m_X$ is insensitive to a change $Y=X^2$, in the sense that $m_Y=m_X^2$. Imagine that $X$ is the  length of some random squares, and $Y$ their area. If an statician is given a sample $\mathbf{X}=\{98,99,101,102\}$, he will estimate that the median of X is 100, so that his median area is 10000. If another statician is given the same data, expressed as areas, $\mathbf{Y}=\{9604,9801,10201,10404\}$, he will get a median area of 10001 (If they had opt for a geometric mean instead of an arithmetic one, they would have agreed).
On the other side, to see that the recipe "Take any number between and including the two middle values" can also be justified, recall that the (probabilistic) median is the value that minimizes the expected value of the absolute prediction error $|x - a|$. Analogously, we'd expect that to find the sample median should be equivalent to find the value that minimizes the average distance to all points, i.e. minimize $\sum |x_i-a|$. And this indeed coincides with the traditional definition of sample median, for odd sample size; and, for even sizes, it's easily seen  that any number "between and including the two middle values" attain this mininum - and hence, is a reasonable sample median.
A: I think you have to take the average of the two middle numbers.
median({1,2,3,4}) = (2+3) / 2 = 2.5
That's what they said me in school.
