Loading TOC...

MarkLogic Server 11.0 Product Documentation
cts.percentile

cts.percentile(
   arg as Number[],
   p as Number[]
) as Sequence

Summary

Returns a sequence of percentile(s) given a sequence of percentage(s). This function works like math:percentile except each item in the sequence is repeated cts:frequency times before calculating the percentile(s). The function returns the empty sequence if either $arg or $p is the empty sequence.

Parameters
arg The sequence of values. The values should be the result of a lexicon lookup.
p The sequence of percentage(s).

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 obj = new Object();
     for (y=0; y < x; y++){
      {obj.int = y}; };
xdmp.documentInsert(fn.concat(x, ".json"), obj);} 

// After creating the above document, run the following:
//
cts.percentile(
  cts.values([cts.jsonPropertyReference("int", ["type=int"])]),
  [0.25,0.5,0.75])
=>
1.5
4.5
7.5

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