Loading TOC...

cts:stddev

cts:stddev(
   $range-index as cts:reference,
   [$options as xs:string*],
   [$query as cts:query?],
   [$forest-ids as xs:unsignedLong*]
) as xs:double?

Summary

Returns a frequency-weighted sample standard deviation given a value lexicon. This function works like math:stddev except each item in the lexicon is counted cts:frequency times. This function performs the calculation in parallel in all data nodes then aggregates the values. The function returns the empty sequence if the lexicon contains no value.

Parameters
range-index Reference to a range index. The type of the range index must be numeric.
options Same as the "options" parameter in cts:aggregate.
query Same as the "query" parameter in cts:aggregate.
forest-ids Same as the "forest-ids" parameter in cts:aggregate.

Example

xquery version "1.0-ml";

(:
   This query assumes an int range index
   is configured in the database. It
   generates some sample data and then
   performs the aggregation in a separate
   transaction.
:)
for $x in 1 to 10
return
xdmp:document-insert(fn:concat($x, ".xml"),
<my-element>{
  for $y in 1 to $x
  return <int>{$x}</int>
}</my-element>);


cts:stddev(
  cts:element-reference(xs:QName("int"),"type=int"),
    ("item-frequency","concurrent")),
cts:stddev(
  cts:element-reference(xs:QName("int"),"type=int"),
    ("fragment-frequency","concurrent"))
=>
2.47206616236522
3.02765035409749

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.