math median

For math.

Computes the median of a list of numbers.

Command Type

built-in

Signature

> math median {flags} ...rest

Parameters

  • ...rest: The cell-paths/columns to operate on.

Input/output types:

input output
list<number> number
list<duration> duration
list<filesize> filesize
range number
table record
record record

Examples

Compute the median of a list of numbers.

> [3 8 9 12 12 15] | math median
10.5

Compute the medians of the columns of a table.

> [{a: 1 b: 3} {a: 2 b: -1} {a: -3 b: 5}] | math median
╭───┬───╮
│ a │ 1 │
│ b │ 3 │
╰───┴───╯

Find the median of a list of file sizes.

> [5KB 10MB 200B] | math median
5.0 kB

Compute the median of list-valued columns in a record.

> {alice: [3 1 2], bob: [4 5 6]} | math median
╭───────┬───╮
│ alice │ 2 │
│ bob   │ 5 │
╰───────┴───╯

Compute the median of a single column using a cell path.

> {alice: [3 1 2], bob: [4 5 6]} | math median alice
╭───────┬───────────╮
│ alice │ 2         │
│       │ ╭───┬───╮ │
│ bob   │ │ 0 │ 4 │ │
│       │ │ 1 │ 5 │ │
│       │ │ 2 │ 6 │ │
│       │ ╰───┴───╯ │
╰───────┴───────────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.