<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.avg.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.avg</api:function-name><api:suggest>fn.avg</api:suggest><api:suggest>fn</api:suggest><api:suggest>avg</api:suggest><api:function-link mode="xquery" fullname="fn:avg">/apidoc/8.0/fn:avg.xml</api:function-link><api:function mode="javascript" name="avg" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.avg"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
Returns the average of the values in the input sequence $arg, that is, the sum
of the values divided by the number of values.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $arg is the empty sequence, the empty sequence is returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $arg contains values of type xs:untypedAtomic they are cast to xs:double.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the above conditions are not met, then a type error is raised [err:FORG0006].
</p><p xmlns="http://www.w3.org/1999/xhtml">
Otherwise, returns the average of the values computed as sum($arg) div
count($arg).
</p><p xmlns="http://www.w3.org/1999/xhtml">
For detailed type semantics, see
<a href="http://www.w3.org/TR/xquery-semantics/#sec_fn_aggregates">Section
7.2.10 The fn:min, fn:max, fn:avg, and fn:sum functions[FS]</a>.
</p>
</api:summary><api:params><api:param name="arg" type="ValueIterator | Array" class="javascript"><api:param-description>
  The sequence of values to average.
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>ValueIterator | Array</api:param-type></api:param></api:params><api:return>xs.anyAtomicType?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var seq3 = [3, 4, 5];
fn.avg(seq3);
=&gt; 4.0

fn.avg(null);
=&gt; ()

</pre>
</api:example></api:function></api:function-page>