This library requires DataWeave version 2.10 or higher.
1. org::mule::weave::Statistics
This module provides a basic set of functionalities to analyze datasets of values, numeric or not.
1.1. Functions
1.1.1. frequencies
frequencies<T>(values: Array<T>): Array<{ value: T, occurrences: Number }>
The frequencies function returns the number of occurrences of each
distinct element on values.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<T> |
Example
This example shows how the frequencies behaves under an array of numbers.
1
2
3
4
5
6
%dw 2.0
output application/json
import frequencies from org::mule::weave::Statistics
---
frequencies([1, 2, 11, 1, 1, 2])
1
2
3
4
5
[
{value: 1, occurrences: 3},
{value: 2, occurrences: 2},
{value: 11, occurrences: 1}
]
1.1.2. mean
mean(values: Array<Number>): Number | Null
The mean function returns the mean of an array of numbers,
or null if the array is empty.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<Number> |
Example
This example shows how the mean behaves over an array with numbers.
1
2
3
4
5
6
%dw 2.0
output application/json
import mean from org::mule::weave::Statistics
---
mean([1, 2, 3, 4, 5])
1
3
Example
This example shows how the mean behaves under an empty array.
1
2
3
4
5
6
%dw 2.0
output application/json
import mean from org::mule::weave::Statistics
---
mean([]) default "N/A"
1
"N/A"
1.1.3. median
median(values: Array<Number>): Number | Null
The median function returns the point on the medium of the population.
If the length of the array is even, the average of the two medium points is returned.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<Number> |
Example
This example shows how the median behaves under different inputs.
1
2
3
4
5
6
%dw 2.0
output application/json
import median from org::mule::weave::Statistics
---
median([3, 1, 4])
1
3
1.1.4. mode
mode<T>(values: Array<T>): T | Null
The mode function returns the most common value on the array
of values.
If there are more than one values with the most number of occurrences, the first one will be returned.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<T> |
Example
This example shows how the mode behaves under an arbitrary array.
1
2
3
4
5
6
%dw 2.0
output application/json
import mode from org::mule::weave::Statistics
---
mode(["hello", "world", "data", "weave", "data"])
1
"data"
1.1.5. modes
modes<T>(values: Array<T>): Array<T>
The modes function returns the values with the most
number of occurrences.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<T> |
Example
This example shows how the modes behaves under an arbitrary array.
1
2
3
4
5
6
%dw 2.0
output application/json
import mode from org::mule::weave::Statistics
---
modes(["hello", "world", "data", "weave", "data", "hello"])
1
["hello", "data"]
1.1.6. quantilesOf
quantilesOf(n: Number, values: Array<Number>): Array<Number> | Null
The quantilesOf function returns the points that separate the
values in n parts of equal size.
If the middle point of two points is taken, it’ll be taken doing the average between both points.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<Number> |
|
n |
Number |
Example
This example shows how the quantilesOf behaves under an arbitrary array.
1
2
3
4
5
6
%dw 2.0
output application/json
import * from org::mule::weave::Statistics
---
3 quantilesOf [1, 2, 3, 4, 5]
1
[2, 4]
1.1.7. stdev
stdev(values: Array<Number>): Number | Null
The stdev function returns the standard deviation of the
given set of values.
The standard deviation is defined as the square root of the variance.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<Number> |
Example
This example shows how the stdev behaves under an arbitrary array.
1
2
3
4
5
6
%dw 2.0
output application/json
import stdev from org::mule::weave::Statistics
---
stdev([1, 2, 3, 2])
1
0.7071067811865475244008443621048491
1.1.8. variance
variance(values: Array<Number>): Number | Null
The variance function returns the variance of the given set of
values.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Array<Number> |
Example
This example shows how the variance behaves under an arbitrary array.
1
2
3
4
5
6
%dw 2.0
output application/json
import variance from org::mule::weave::Statistics
---
variance([1, 2, 3, 2])
1
0.5