math mode

For math.

Returns the most frequent element(s) from a list of numbers or tables.

Command Type

built-in

Signature

> math mode {flags} ...rest

Parameters

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

Input/output types:

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

Examples

Compute the mode(s) of a list of numbers.

> [3 3 9 12 12 15] | math mode
╭───┬────╮
│ 0 │  3 │
│ 1 │ 12 │
╰───┴────╯

Compute the mode(s) of the columns of a table.

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

Compute the mode(s) of list-valued columns in a record.

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

Compute the mode(s) of a single column using a cell path.

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

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