Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Median and Mode

edited April 2012 in RAP
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;

--

Comments

  • edited April 2012
    Hi David,

    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.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited April 2012
    Hi Nico.

    Thanks for the feedback. I will take a stab at it with TStringList. I
    assume all the properties are available, like Sorted, etc.

    David.

  • edited April 2012
    Hi Nico.

    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?


  • edited April 2012
    Hi David,

    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.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.