math variance

For math.

Returns the variance of a list of numbers or of each column in a table.

Command Type

built-in

Signature

> math variance {flags} ...rest

Flags

  • --sample, -s: Calculate sample variance (i.e. using N-1 as the denominator).

Parameters

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

Input/output types:

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

Examples

Get the variance of a list of numbers.

> [1 2 3 4 5] | math variance
2.0

Get the sample variance of a list of numbers.

> [1 2 3 4 5] | math variance --sample
2.5

Compute the variance of each column in a table.

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

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

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

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

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

Variance of filesizes is a number of base units squared (bytes²).

> [1KB 3KB] | math variance
1000000.0

Notes

For filesize and duration inputs, variance is computed in base units (bytes and nanoseconds) and returned as a plain number. There is no squared unit type in Nushell, so the result is the variance of the underlying byte or nanosecond values (B² or ns²), not of the display unit used when the values were written.

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