median

Computes the median of the values in this iterable.

The median is the middle value when the data is sorted. For an even number of elements, it is the average of the two middle values. Unlike the mean, the median is robust to outliers.

Example:

listOf(3.0, 1.0, 2.0).median()      // 2.0
listOf(1.0, 2.0, 3.0, 4.0).median() // 2.5

Return

the median of the elements.


Computes the median of the values in this array.

The median is the middle value when the data is sorted. For an even number of elements, it is the average of the two middle values. Uses introselect (O(n) expected time) instead of a full sort for efficiency.

Example:

doubleArrayOf(3.0, 1.0, 2.0).median()      // 2.0
doubleArrayOf(1.0, 2.0, 3.0, 4.0).median() // 2.5

Return

the median of the array elements.


Computes the median of the values in this sequence.

The sequence is materialized internally. See DoubleArray.median for details.

Return

the median of the elements.


@JvmName(name = "medianOfLong")
fun Iterable<Long>.median(): Double(source)

Computes the median of the Long values.

Values are converted to Double internally. Long values whose absolute value exceeds 2^53 (9,007,199,254,740,992) may lose precision in the least-significant digits.

Example:

listOf(1L, 2L, 3L, 4L).median() // 2.5

Return

the median of the Long values as a Double.


@JvmName(name = "medianOfInt")
fun Iterable<Int>.median(): Double(source)

Computes the median of the Int values.

Values are converted to Double internally. The conversion is exact for all Int values.

Example:

listOf(1, 2, 3, 4).median() // 2.5

Return

the median of the Int values as a Double.