rank

Given an input array, outputs an array containing the rank from [1, input.length] corresponding to each element. Ties are dealt with by averaging. This function does not reorder the input range. Return type is float[] by default, but if you are sure you have no ties, ints can be used for efficiency (in which case ties will not be averaged), and if you need more precision when averaging ties, you can use double or real.

Works with any input range.

Ret[]
rank
(
alias compFun = "a < b"
Ret = double
T
)
(
,
Ret[] buf = null
)
if (
isInputRange!(T) &&
is(typeof(input.front < input.front))
)

Examples

uint[] test = [3, 5, 3, 1, 2];
assert(rank!("a < b", float)(test) == [3.5f, 5f, 3.5f, 1f, 2f]);
assert(test == [3U, 5, 3, 1, 2]);

Meta