The median of a set of numbers is the middle value. If the set of numbers has an even amount, the median is the average of the two middle numbers. For more information, see Wikipedia. This tutorial will explain how to find the median of numbers.

## Sorting the Values

*Main article: Sorting Values*

The first step in finding the median is to sort the data from least to greatest. Doing this first will make this finding the median much easier.

## Finding the Median

First, sort the values in order.

Once the values have been sorted, use the following script to get the median. Remember that the list "Data" contains the set of values. The variables "Med1" and "Med2" represent the values that will be used to solve for the median.

set [Med1 v] to (item ((length of [data v]) / (2)) of [data v]) set [Med2 v] to (item (((length of [data v]) / (2)) + (1)) of [data v]) if < ((length of [data v]) mod (2)) = (0)> then say (join [median=] (((Med1) + (Med2)) / (2))) for (2) secs else say (join [median=] (item (((length of [data v]) / (2)) + (0.5)) of [data v])) for (2) secs end