math avg

For math.

Returns the average of a list of numbers.

Command Type

built-in

Signature

> math avg {flags} ...rest

Parameters

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

Input/output types:

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

Examples

Compute the average of a list of numbers.

> [-50 100.0 25] | math avg
25.0

Compute the average of a list of durations.

> [2sec 1min] | math avg
31sec

Compute the average of each column in a table.

> [[a b]; [1 2] [3 4]] | math avg
╭───┬───╮
│ a │ 2 │
│ b │ 3 │
╰───┴───╯

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

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

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

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

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