DataWeave Analytics Library icon

DataWeave Analytics Library

(1 review)

Statistics

analytics::Statistics

This module provides basic functionality for analyzing
datasets of numeric and non-numeric values.

Index

Functions

NameDescription
frequenciesReturns the number of occurrences of each
distinct element in an array.
meanReturns the mean of an array of numbers,
or null if the array is empty.
medianReturns the median value of an array.
modeReturns the most common value in the array
of values.
modesReturns the values with the most
number of occurrences.
quantilesOfReturns the points that separate the
values in n parts of equal size.
stdevReturns the standard deviation of the
given set of values.
varianceReturns the variance of the given set of
values.

Functions

frequencies ↑↑

frequencies<T>(values: Array<T>): Array<{ value: T, occurrences: Number }>

Returns the number of occurrences of each
distinct element in an array.

Parameters
NameTypeDescription
valuesArray<T>The array of values to evaluate.
Example

This example shows how frequencies behaves with an array of numbers.

Source
%dw 2.0
output application/json

import frequencies from analytics::Statistics
---
frequencies([1, 2, 11, 1, 1, 2])
Output
[
  {value: 1, occurrences: 3},
  {value: 2, occurrences: 2},
  {value: 11, occurrences: 1}
]

frequencies(values: Null): Null

Helper function that enables frequencies to work with a null value.


mean ↑↑

mean(values: Array<Number>): Number | Null

Returns the mean of an array of numbers,
or null if the array is empty.

Parameters
NameTypeDescription
valuesArray<Number>Array of numeric or null values.
Example

This example shows how mean behaves with an array of numbers.

Source
%dw 2.0
output application/json

import mean from analytics::Statistics
---
mean([1, 2, 3, 4, 5])
Output
3
Example

This example shows how mean behaves with an empty array.

Source
%dw 2.0
output application/json

import mean from analytics::Statistics
---
mean([]) default "N/A"
Output
"N/A"

mean(values: Null): Null

Helper function that enables mean to work with a null value.


median ↑↑

median(values: Array<Number>): Number | Null

Returns the median value of an array.

If the length of the array is even, returns the average of the two median values.

Parameters
NameTypeDescription
valuesArray<Number>Array of numeric or null values.
Example

This example shows how median behaves.

Source
%dw 2.0
output application/json

import median from analytics::Statistics
---
median([3, 1, 4])
Output
3

median(values: Null): Null

Helper function that enables median to work with a null value.


mode ↑↑

mode<T>(values: Array<T>): T | Null

Returns the most common value in the array
of values.

If more than one value has the most number of
occurrences, the first value is returned.

Parameters
NameTypeDescription
valuesArray<T>Array of values to evaluate.
Example

This example shows how mode behaves with an arbitrary array.

Source
%dw 2.0
output application/json

import mode from analytics::Statistics
---
mode(["hello", "world", "data", "weave", "data"])
Output
"data"

mode(values: Null): Null

Helper function that enables mode to work with a null value.


modes ↑↑

modes<T>(values: Array<T>): Array<T>

Returns the values with the most
number of occurrences.

Parameters
NameTypeDescription
valuesArray<T>Array of values to evaluate.
Example

This example shows how modes behaves with an arbitrary array.

Source
%dw 2.0
output application/json

import mode from analytics::Statistics
---
modes(["hello", "world", "data", "weave", "data", "hello"])
Output
["hello", "data"]

modes(values: Null): Null

Helper function that enables modes to work with a null value.


quantilesOf ↑↑

quantilesOf(n: Number, values: Array<Number>): Array<Number> | Null

Returns the points that separate the
values in n parts of equal size.

If the middle point of two points is taken, the function returns the
average of both points.

Parameters
NameTypeDescription
valuesArray<Number>Array of numeric values to evaluate.
nNumberThe desired number of quantiles.
Example

This example shows how the quantilesOf behaves with an arbitrary array.

Source
%dw 2.0
output application/json

import * from analytics::Statistics
---
3 quantilesOf [1, 2, 3, 4, 5]
Output
[2, 4]

quantilesOf(n: Any, values: Null): Null

Helper function that enables quantilesOf to work with a null value.


stdev ↑↑

stdev(values: Array<Number>): Number | Null

Returns the standard deviation of the
given set of values.

The standard deviation is defined as the square root
of the variance.

Parameters
NameTypeDescription
valuesArray<Number>Array of numbers to evaluate.
Example

This example shows how stdev behaves with an arbitrary array.

Source
%dw 2.0
output application/json

import stdev from analytics::Statistics
---
stdev([1, 2, 3, 2])
Output
0.7071067811865475244008443621048491

stdev(values: Null): Null

Helper function that enables stdev to work with a null value.


variance ↑↑

variance(values: Array<Number>): Number | Null

Returns the variance of the given set of
values.

Parameters
NameTypeDescription
valuesArray<Number>Array of numbers to evaluate.
Example

This example shows how the variance behaves with an arbitrary array.

Source
%dw 2.0
output application/json

import variance from analytics::Statistics
---
variance([1, 2, 3, 2])
Output
0.5

variance(values: Null): Null

Helper function that enables variance to work with a null value.



Reviews

TypeDataWeave Library
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onMar 23, 2022
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.1
1.0.0