rankn
The rankn function returns the ranked value of a general lua table that may contain a multi-dimensional array or a mixture of numbers, strings, named keys, and sub-tables. Only numeric values found in the table are used in the calculation. The rank is specified as a percentile, between 0 and 100. By definition, the minimum value corresponds to rank = 0, the median value corresponds to rank = 50, and the maximum value corresponds to rank = 100. Since an array is a specific type of table that contains only numbers or sub-tables, this function can also be used for arrays.
nMedian = rankn( tbl, pct )
tbl is a general lua table.
pct is the percentile for calculating the rank.
The following script returns the of a 1-dimensional array containing 1 million random numbers. The random number generator produce a uniform distribution in the range [0, 1] with a mean value of 0.5. Within statistical noise, the 50th percentile should be close to 0.5.
|
-- create an array of numbers |
|
-- find the 50th percentile value |
|
|
|
-- Result: Val = 0.500739, Med=.500739 |
The next example computes the 30th percentile and median of an ugly, complex table:
|
|
|
-- find the 30th percentile value |
|
-- result: Val = 5.4 |
Table and Array Functions, mediann
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics,
Inc. All Rights Reserved.