Investment Studio > Expressions > Functions > Statistical > FREQUENCY

float array[*][1] frequency(float array data, float array bins)

Returns a column vector containing the number of data points falling within each specified bin range.

All array elements are converted to float, with exclusion if conversion fails.

data may be empty, in which case the result vector will contain zero elements only.

The bin array contains upper bin limits and must be sorted in ascending order. Given N bin elements, any data value <= bin[1] is assigned to the first bin; any data value > bin[N] is assigned to bin N + 1. The result vector therefore contains N + 1 elements.

bin may be two-dimensional, in which case the order of appearance of each element (reading from left to right, top to bottom) becomes the order of the corresponding bin.

bin may also be empty, in which case the function simply returns the number of elements in the data array (no bin boundaries Û a single bin stretching from -¥ to +¥).

Examples

=frequency({7, 2, 5, 8, 2, 9, 4, 2, 3, 0, 4, 2, 7, 1}, {1, 2, 4, 8})

returns {{2}, {4}, {3}, {4}, {1}}. The five bins cover the ranges ]-¥, 1]; ]1, 2]; ]2, 4]; ]4, 8] and ]8, +¥[. The two data elements assigned to the first bin are the ones with values 0 and 1; the single data element assigned to the last bin is the one with value 9.

=frequency({7, 2, 5, 8, 2, 9, 4, 2, 3, 0, 4, 2, 7, 1}, {})

returns 14 (the number of elements in the data array).

=frequency({}, {1, 2, 4, 8})

returns {{0}, {0}, {0}, {0}, {0}}.

See also count, counta, countblank, countif.