From Test-Scratch-Wiki

The median of a set of five numbers.

This tutorial will explain how to find the median of numbers. 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.

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

Once you have sorted the values, you can 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

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.