math.listMean: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Fixing usage)
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 6: Line 6:


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


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: list1 = "1,2,3,3,10"]
[h: list1 = "1,2,3,3,10"]
[r: math.listMean(list1)]
[r: math.listMean(list1)]
[h: list2 = "1#2#3#4#1#2#3#0#2"]
[h: list2 = "1#2#3#4#1#2#3#0#2"]
[r: math.listMean(list2,"#")]
[r: math.listMean(list2,"#")]
</source>
</syntaxhighlight>
Returns:
Returns:
<pre>
<pre>

Latest revision as of 23:12, 14 March 2023

math.listMean() Function

Introduced in version 1.7
Calculates the arithmetic mean of the contents of a String List. Only allows numeric elements - any non-numeric values will produce an error. The mean is equal to the sum of all the list's contents divided by the number of elements.

Usage

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

Examples

[h: list1 = "1,2,3,3,10"]
[r: math.listMean(list1)]
[h: list2 = "1#2#3#4#1#2#3#0#2"]
[r: math.listMean(list2,"#")]

Returns:

 3.8
 2