Investment Studio > Expressions > Functions > Statistical > RANK
integer rank(float x, float array data, integer order = 0)
Returns the rank of x in the data set. The rank is the position in data which would be occupied by x if data were sorted by size in the specified order.
All elements in data are converted to floats, with exclusion if conversion fails. Duplicate numbers get the same rank, but do increment the rank of subsequent list elements like all other list elements. For instance, if a duplicate 6 with rank 3 is followed by a 7, the 7 would have rank 5; no list element would have rank 4.
x is the value for which the rank in data is to be computed. It must match a value in data.
order specifies the sort order used to determine the rank. If order = 0, the function result is the position in data which would be occupied by number if data were sorted by size in descending order. If order <> 0, ascending sort order is used. If order is omitted, it defaults to 0.
Examples
=rank(4, {1, 2, 3, 4, 5})
returns 2: order = 0 (implied by omission) yields the descending list {5, 4, 3, 2, 1}, where the position of 4 is 2;
=rank(7.4, {1, 2, 3, 4, 5, 6, 7, 8, 9})
is an error (#VALUE!) since there is no match to 7.4 in the list;
=rank(4, {1, 2, 3, 3, 4, 5, 6, 7, 8}, 1)
returns 5 (order = 1 yields ascending sort order; duplicate 3 with rank 3 means no data element has rank 4).
See also average, count, frequency, geomean, harmean, large, max, median, min, percentile, percentrank, quartile, small, trimmean.