Median and Mode
Has anyone ever calculated Median and Mode statistics using RAP?
I can probably figure it out in Delphi, but not sure how to accomplish
it in RAP without a pass thru function.
In Delphi, I can do something like the following for the median:
uses Generics.Collections, Types;
function Median(aArray: TDoubleDynArray): Double;
var
lMiddleIndex: Integer;
begin
TArray.Sort(aArray);
lMiddleIndex := Length(aArray) div 2;
if Odd(Length(aArray)) then
Result := aArray[lMiddleIndex]
else
Result := (aArray[lMiddleIndex - 1] + aArray[lMiddleIndex]) / 2;
end;
--
I can probably figure it out in Delphi, but not sure how to accomplish
it in RAP without a pass thru function.
In Delphi, I can do something like the following for the median:
uses Generics.Collections, Types;
function Median(aArray: TDoubleDynArray): Double;
var
lMiddleIndex: Integer;
begin
TArray.Sort(aArray);
lMiddleIndex := Length(aArray) div 2;
if Odd(Length(aArray)) then
Result := aArray[lMiddleIndex]
else
Result := (aArray[lMiddleIndex - 1] + aArray[lMiddleIndex]) / 2;
end;
--
This discussion has been closed.
Comments
From RAP, you have access to the TStringList object. It may be
possible to use this to keep track of each value that later needs to be
calculated. Otherwise, a passthru would be the easier solution.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for the feedback. I will take a stab at it with TStringList. I
assume all the properties are available, like Sorted, etc.
David.
I am trying to call ValueFromIndex of a TStringList, but it will not
compile. It says it expects ( or [ but found ValueFromIndex instead.
Does the TStringList in RAP support Name Value pairs and using the
properties Values and ValueFromIndex?
TStringList in RAP does not currently support ValueFromIndex but does
allow access to the Values property. I will see about adding
ValueFromIndex for a later release.
Thanks for the feedback.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com