rank

fun DoubleArray.rank(tieMethod: TieMethod = TieMethod.AVERAGE): DoubleArray(source)

Computes ranks for each element based on its relative position when sorted.

Ranking assigns a 1-based position to each value according to its magnitude. The smallest value gets rank 1 (or a tie-adjusted rank), and ranks increase with value. The tieMethod parameter controls how equal values share ranks.

Example:

doubleArrayOf(3.0, 1.0, 4.0, 1.0, 5.0).rank() // [3.0, 1.5, 4.0, 1.5, 5.0]
doubleArrayOf(3.0, 1.0, 1.0, 5.0).rank(TieMethod.DENSE) // [2.0, 1.0, 1.0, 3.0]

Return

an array of ranks in the same order as the input, where each element's rank reflects its position in the sorted order.

Parameters

tieMethod

how to handle tied (equal) values. Defaults to TieMethod.AVERAGE, which assigns each tied element the mean of the positions they occupy.

Throws

if the array is empty.

if the array contains NaN.


fun Iterable<Double>.rank(tieMethod: TieMethod = TieMethod.AVERAGE): List<Double>(source)

Computes ranks for each element based on its relative position when sorted.

This is a convenience overload that accepts any Iterable. The collection is materialized to a DoubleArray internally.

Return

a list of ranks in the same order as the input.

Parameters

tieMethod

how to handle tied (equal) values. Defaults to TieMethod.AVERAGE.

See also

Throws

if the collection is empty.

if the collection contains NaN.