Rev Language Reference

median - Median of a set of numbers

Finds the median of a sorted vector of numbers.

median(Real[] x)

Arguments

 x : Real[] (pass by const reference) A vector of numbers.

Details

The vector is sorted when median is used finding the number of the sorted values with an equal amount of numbers that are greater than or less than that value. If the length of the vector is even, there will be no such value. In that case, the two are averaged automatically.

Example

a = v(5,3,2,6,8)
median(a)
# 5 is the result
b = v(1,1,2,3,5,8)
median(b)
# 2.5 is the result