Version:

Loading TOC...

fn.avg( $arg as Sequence | Array ) as xs.anyAtomicType?

Returns the average of the values in the input sequence $arg, that is, the sum of the values divided by the number of values.

If $arg is the empty sequence, the empty sequence is returned.

If $arg contains values of type xs:untypedAtomic they are cast to xs:double.

Duration values must either all be xs:yearMonthDuration values or must all be xs:dayTimeDuration values. For numeric values, the numeric promotion rules defined in 6.2 Operators on Numeric Values are used to promote all values to a single common type. After these operations, $arg must contain items of a single type, which must be one of the four numeric types,xs:yearMonthDuration or xs:dayTimeDuration or one if its subtypes.

If the above conditions are not met, then a type error is raised [err:FORG0006].

Otherwise, returns the average of the values computed as sum($arg) div count($arg).

For detailed type semantics, see Section 7.2.10 The fn:min, fn:max, fn:avg, and fn:sum functions[FS].

Parameters | |
---|---|

$arg | The sequence of values to average. |

var seq3 = [3, 4, 5]; fn.avg(seq3); => 4.0 fn.avg(null); => ()

Copyright © 2017 MarkLogic Corporation. MARKLOGIC is a
registered trademark of MarkLogic Corporation.

## Comments