Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

name: op-agg-median
description: 50th percentile of the field; requires sorting the full value set.
kind: operator
category: AGG
operator: AGG_MEDIAN
type: reference
applies_to: process, compose, predict
examples_tags: [distribution-shape, buffered-pipeline]

Use when

Middle value of a numeric field once sorted: the typical row, not pulled by a few extreme values.

Questions it answers:

  • What is the typical household income in each region?
  • What is the typical delivery time when a few deliveries take weeks?

Use something else:

  • AGG_PERCENTILE when you want a value other than the middle, such as the 90th percentile.
  • AGG_MODE when the field holds categories rather than numbers.

Params

Weight-aware ("weight": null opts out): Hmisc wtd.quantile — sort by value; h = 0.5·(Σw−1); x(k) = first value with cumulative Σw ≥ k+1 (snapped to an integer within 1e-9); interpolate x(⌊h⌋)..x(⌈h⌉). probability weights first rescaled to Σw = n (rows used) — scale-invariant; frequency weights stay raw = type 7 on duplicated rows. Invalid weights excluded (PULSE_WEIGHT_INVALID_ROWS).

Inputs

ParamAccepted field types
Fieldnumeric (no decimal128): u8/u16/u32/u64, f32/f64, date, datetime, packed_bool, u4

Output

Scalar float64. Per-group when wired under a grouper.

Components

Weighted adds floor sum_weights, n_eff (probability), n_weight_invalid.

Universal floor {n, n_null} plus operator-specific:

KeyTypeNotes
position_lowintLower bracket index (weighted: ⌊h⌋, expanded)
position_highintUpper bracket index (weighted: ⌈h⌉)
medianfloat64Resolved median (linear interpolation)
  • Mergeability: None — exact median needs full sort
  • Streaming: NOT streamable (buffered only).

Gotchas

  • Buffered-only path: full input materialised before sort.
  • Outlier-robust, unlike the mean.

See