Problem : Calculating Median in FoxPro
Does anyone know a way to calculate the median of a group of values in FoxPro? It is not under the math functions.
Solution: Calculating Median in FoxPro
No such function but its math is easy. Select your values into an array and get the element in the middle, if elements count is even then get the average of 2 elements in the middle. ie :
select myField from myTable into array arrNumbers
if alen(arrNumbers) % 2 = 1
lnMedian = arrNumbers[ceiling(alen(arrNumbers)/2)]
lnMedian = ( arrNumbers[alen(arrNumbers)/2] + arrNumbers[alen(arrNumbers)/2+1] ) / 2