normn sdevxn

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.

Syntax

nMedian = rankn( tbl, pct )

bullet.gif    tbl is a general lua table.

bullet.gif    pct is the percentile for calculating the rank.

Examples

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.

t = random( 1000000 )

-- create an array of numbers

r = rankn( t, 50 )

-- find the 50th percentile value

m = mediann( t )

 

Printf("Val=%lg, Med=%lg\n", r, m )

-- Result: Val = 0.500739, Med=.500739

  

The next example computes the 30th percentile and median of an ugly, complex table:

t = { 6, -2, 15, "a", {5,"b"}, c="5.4" }

 

r = rankn(t, 30)

-- find the 30th percentile value

Printf("Val= %lg\n", r, m )

-- result: Val = 5.4

Related Topics

Table and Array Functions

mediann

 


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.