Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generating Statistics Info
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00223474
Message ID:
00223545
Views:
25
>>Median is a value in a series of numbers where there are an equal number of values less than and greater than. Not knowing if there may be duplicate values makes this a bit harder. I'd try for the arithmetic mean (by getting the minimumand maximum values via CALCULATE) as a starting point. Where to go from there, I haven't figured out.:-)
>
>You guys are making it too difficult :) It's just the (n+1)/2 value of an ordered list if odd # elements, or average of middle two values in the case of an even number of elements...Cetin is close, but no need to use array, I don't think...

Hi Bruce,

As I said to Cetin, I'm no statistian, so I'll humbly bow out here (but not without taking one more shot< g >).
LOCAL lnresult, lntotal, lnmin, lnmax
lnresult = 0
DIMENSION a_values[1]
SELECT nField;
  FROM MyTable;
  ORDER BY nField;
  INTO CURSOR MyValues
lntotal = _TALLY
IF lntotal > 0
  IF (lntotal / 2) = INT(lntotal / 2)
    * Even number of records
    GOTO lntotal / 2
    lnmin = MyValues.nField
    SKIP
    lnmax = MyValues.nField
    lnresult = lnmin + ((lnmax - lnmin) / 2)
  ELSE
    * Odd number
    GOTO CEILING(lntotal / 2)
    lnresult = MyValues.nField
  ENDIF
ENDIF
RETURN lnresult
How's this?
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform