Loading TOC...

cts.median

cts.median(
   $arg as Number[]
) as Number?

Summary

Returns a frequency-weighted median of a sequence. This function works like math:median except each item in the sequence is repeated cts:frequency times before calculating the median. If $arg is the empty sequence, the function returns the empty sequence.

Parameters
$arg The sequence of values. The values should be the result of a lexicon lookup.

Usage Notes

This function is designed to take a sequence of values returned by a lexicon function (for example, cts:element-values); if you input non-lexicon values, the result will be the empty sequence.

Example

//  This query assumes an element range index of type 'int'
//  is configured for the 'int' element in the database. It
//  generates some sample data and then performs the aggregation
//  in a separate transaction.

declareUpdate();

for (x=1; x<11; x++) {
  var o = new Object();
  o.int = [];
  for (y=x; y<11; y++) { 
    o.int.push(y);    
  };
  xdmp.documentInsert((x + ".json"), o); 
};

******
// Run the following query:

var res = new Array();
res.push(cts.median(cts.values(
  cts.jsonPropertyReference("int", "type=int"), null,
                            ["item-frequency"])));
res.push(cts.median(cts.values(
  cts.jsonPropertyReference("int", "type=int"), null,
                            ["fragment-frequency"])));
res;
=>
[7, 7]


Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy