MovingMedian[list,r]
gives the moving median of list, computed using spans of r elements.
MovingMedian
MovingMedian[list,r]
gives the moving median of list, computed using spans of r elements.
Details
- MovingMedian gives a list of the medians of elements in list taken in blocks of length r. »
- MovingMedian gives a list of length Length[list]-r+1.
- MovingMedian works with SparseArray and TimeSeries objects. »
Examples
open all close allBasic Examples (2)
Scope (5)
Compute moving medians for any numeric data:
MovingMedian[{1, E, Sqrt[Pi], 2, 10, E ^ 2}, 3]Obtain results at machine precision:
MovingMedian[N[{1, 5, 7, 3, 6, 2}], 3]Obtain results for lists of any precision:
MovingMedian[N[{1, 5, 7, 3, 6, 2}, 25], 3]Moving medians of matrices are matrices:
data = RandomReal[5, {10, 2}]MovingMedian[data, 4]Moving median of a TimeSeries:
ts = TemporalData[TimeSeries, {{{0., 0.24628521289687533, 0.3703374944231774, 0.4717582177179417,
0.3940302965227978, 0.5618705948857727, 0.2584747970316238, 0.5201131120145466,
0.8157396141130544, 0.7246714521345359, 0.8447350569180434, 0.756 ... 652867661, -2.5881471131731897, -2.578676175222997,
-2.2907776293136597}}, {{0, 1., 0.01}}, 1, {"Continuous", 1}, {"Continuous", 1}, 1,
{ValueDimensions -> 1, ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False,
10.1];Show[ListPlot[ts], ListLinePlot[Table[MovingMedian[ts, k], {k, {2, 5, 15}}]]]Generalizations & Extensions (2)
Compute results for a SparseArray:
sp = SparseArray[{{i_, i_} :> i, {i_, j_} /; j < i :> (i + j)}, {100, 10}]MovingMedian[sp, 5]Compute the moving median of a numeric TimeSeries for various window lengths:
ts = TimeSeries[TimeEventSeries`TimestampData[Association["UniformlySpacedQ" -> True, "Count" -> 61,
"Endpoints" -> TabularColumn[Association["Data" -> {{0., 0.6}, {}, None},
"ElementType" -> "Real64"]], "MinimumTimeIncrement" -> 0.01]],
Ta ... 86436505, -0.344485981849591, -0.32017664131197604,
-0.339944678008272, -0.4962959466695484, -0.5235950374532581, -0.588853370532945,
-0.8359919314597413, -0.9675284674456728}, {}, None}, "ElementType" -> "Real64"]],
Association[]];wspec = {3, 7, 12};res = Table[MovingMedian[ts, k], {k, wspec}];Incomplete windows are dropped, and the result is placed on the right end of each window:
Tabular[Table[{wspec[[i]], res[[i]]["FirstTime"]}, {i, 3}], {"k", "first time"}]Show[ListPlot[ts, PlotStyle -> Gray], ListLinePlot[res, PlotLegends -> wspec]]Applications (2)
data = Range[20] + RandomReal[{-2, 2}, 20]smoothed = MovingMedian[data, 5]ListPlot[data]ListPlot[smoothed]Compute the 100-day moving median of a financial time series:
data = TimeSeries@FinancialData["GE", "Jan. 1, 2000"]DateListPlot[MovingMedian[data, 100]]Properties & Relations (3)
A moving median is a sequence of medians:
MovingMedian[{1, 3, 5, 2, 2, 4, 10, 5}, 4]Table[Median[Take[{1, 3, 5, 2, 2, 4, 10, 5}, {i, i + 3}]], {i, 5}]A two‐term MovingMedian is equivalent to a two‐term MovingAverage:
data = RandomReal[10, 10]MovingMedian[data, 2] == MovingAverage[data, 2]MovingMedian is equivalent to MovingMap of Median:
data = RandomInteger[{-10, 10}, 10]MovingMedian[data, 3]MovingMap[Median, data, Quantity[3, "Events"]]% === %%Possible Issues (1)
History
Text
Wolfram Research (2007), MovingMedian, Wolfram Language function, https://reference.wolfram.com/language/ref/MovingMedian.html.
CMS
Wolfram Language. 2007. "MovingMedian." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MovingMedian.html.
APA
Wolfram Language. (2007). MovingMedian. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MovingMedian.html
BibTeX
@misc{reference.wolfram_2026_movingmedian, author="Wolfram Research", title="{MovingMedian}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/MovingMedian.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_movingmedian, organization={Wolfram Research}, title={MovingMedian}, year={2007}, url={https://reference.wolfram.com/language/ref/MovingMedian.html}, note=[Accessed: 12-June-2026]}