math.listMedian: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page Math.listMedian to math.listMedian: Converting page titles to lowercase)
No edit summary
 
Line 6: Line 6:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: result = math.listMedian(list)]
[h: result = math.listMedian(list)]
[h: result = math.listMedian(list, delim)]
[h: result = math.listMedian(list, delim)]
</source>
</syntaxhighlight>


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: list1 = "3,6,2,2"]
[h: list1 = "3,6,2,2"]
[r: math.listMedian(list1)]
[r: math.listMedian(list1)]
[h: list2 = "12#23#3#102#1"]
[h: list2 = "12#23#3#102#1"]
[r: math.listMedian(list2,"#")]
[r: math.listMedian(list2,"#")]
</source>
</syntaxhighlight>
Returns:
Returns:
<pre>
<pre>

Latest revision as of 23:11, 14 March 2023

math.listMedian() Function

Introduced in version 1.7
Calculates the Median of the contents of a String List. The median value is is the value where half the numbers in the list are greater than or equal to it, and the other half are less than or equal to it. The median is calculated by sorting the list contents and picking the middle number if the number of elements is odd, or averaging the two in the middle if the number of elements is even. Only allows numeric elements - any non-numeric values will produce an error.

Usage

[h: result = math.listMedian(list)]
[h: result = math.listMedian(list, delim)]

Examples

[h: list1 = "3,6,2,2"]
[r: math.listMedian(list1)]
[h: list2 = "12#23#3#102#1"]
[r: math.listMedian(list2,"#")]

Returns:

 2.5
 12