avg
The average of a sequence of values
Description
The fn:avg function averages a sequence of values. The $arg sequence can contain a mixture of numeric and untyped values. Numeric values are promoted as necessary to make them all the same type. Untyped values are cast as numeric xs:double values.
The function can also be used on duration values, so the $arg sequence can contain all xs:yearMonthDuration values or all xs:dayTimeDuration values (but not a mixture of the two).
Special care should be taken with any “missing” values when using the fn:avg function. See functx:avg-empty-is-zero for more information.
Parameters |
Description |
---|---|
arg:numeric() |
Examples
XPath |
Results |
---|---|
avg( (1, 2, 3, 4, 5) ) |
3 |
avg( (1, 2, 3, (), 4, 5) ) |
3 |
avg((xs:yearMonthDuration(‘P4M’), xs:yearMonthDuration(‘P6M’) ) ) |
P5M |
1.1666666666666667 |
|
avg( () ) |
() |
avg($ordDoc//item/@dept) |
Error FORG0001 |