Skip to contents

A confidentiality-preserving stand-in for a true median: true medians are not published per this project's disclosure rules. Sorts x ascending (NA sorted last, matching Stata's convention — see Pseudocode/00_conventions.md, MISSING), then averages the (up to) 5 values centred on position round_half_up(n_non_missing / 2). This is not interchangeable with a true median except by coincidence — do not replace with median().

Usage

approx_median(x)

Arguments

x

A numeric vector (the values within one group).

Value

A single numeric value (or NA if x has no non-missing values).

Details

Typically used inside a dplyr::summarise() / grouped aggregation, one call per output cell, rather than reproducing the source's compute-then-collapse-then-mean row-broadcast mechanics (which reduce to exactly this value).