# Statistics - Median

The median is a type of average value, which describes where the center of the data is located.

## Median

The median is the middle value in a data set ordered from low to high.

## Finding the Median

The median can only be calculated for numerical variables.

The formula for finding the middle value is:

$$\displaystyle \frac{n + 1}{2}$$

Where $$n$$ is the total number of observations.

If the total number of observations is an odd number, the formula gives a whole number and the value of this observation is the median.

13, 21, 21, 40, 48, 55, 72

Here, there are 7 total observations, so the median is the 4th value:

$$\displaystyle \frac{7 + 1}{2} = \frac{8}{2} = 4$$

The 4th value in the ordered list is 40, so that is the median.

If the total number of observations is an even number, the formula gives a decimal number between two observations.

13, 21, 21, 40, 42, 48, 55, 72

Here, there are 8 total observations, so the median is between the 4th and 5th values:

$$\displaystyle \frac{8 + 1}{2} = \frac{9}{2} = 4.5$$

The 4th and 5th values in the ordered list is 40 and 42, so the median is the mean of these two values. That is, the sum of those two values divided by 2:

$$\displaystyle \frac{40+42}{2} = \frac{82}{2} = \underline{41}$$

Note: It is important that the numbers are ordered before you can find the median.

## Finding the Median with Programming

The median can easily be found with many programming languages.

Using software and programming to calculate statistics is more common for bigger sets of data, as finding it manually becomes difficult.

### Example

With Python use the NumPy library median() method to find the median of the values 13, 21, 21, 40, 42, 48, 55, 72:

import numpy

values = [13,21,21,40,42,48,55,72]

x = numpy.median(values)

print(x)
Try it Yourself »

### Example

Use the R median() function to find the median of the values 13, 21, 21, 40, 42, 48, 55, 72:

values <- c(13,21,21,40,42,48,55,72)

median(values)
Try it Yourself »