Wolfram Research

Function Repository Resource:

CumulativeAverages

Source Notebook

Calculate the cumulative averages of a list

Contributed by: Sander Huisman

ResourceFunction["CumulativeAverages"][list]

calculates the cumulative averages of list.

Details and Options

ResourceFunction["CumulativeAverages"] calculates the average up to a certain time. The nth element of the output is given by Mean[{e1,e2,…,ei}], where ei is the ith element of list. So the nth output element is given as .

Examples

Basic Examples

Find the averages up to the nth element:

In[1]:=
ResourceFunction[
 "CumulativeAverages"][{1, 2, 3, 2, 3, 2, 1, 2, 3, 4, 3, 2}]
Out[1]=

Use a symbolic input:

In[2]:=
ResourceFunction["CumulativeAverages"][{a, b, c, d, e, f}]
Out[2]=

Compute the cumulative averages of the digits of Pi:

In[3]:=
digits = N@First[RealDigits[Pi, 10, 1000]];
cma = ResourceFunction["CumulativeAverages"][digits];
ListPlot[cma, PlotRange -> All, Joined -> True]
Out[5]=

Scope

Use a TimeSeries object:

In[6]:=
ts = TimeSeries[{1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}, {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}}];
ListPlot[ResourceFunction["CumulativeAverages"][ts], PlotRange -> All]
Out[7]=

Use a TimeSeries object from FinancialData:

In[8]:=
goog = FinancialData["GOOGL", {"Jan. 1, 2008", "Jan. 1, 2009"}];
ResourceFunction["CumulativeAverages"][goog]
Out[9]=

Use a TimeSeries object with multiple paths:

In[10]:=
s1 = {2, 1, 6, 5, 7, 4};
s2 = {4, 7, 5, 6, 1, 2};
t = {1, 2, 5, 10, 12, 15};
td = TemporalData[{s1, s2}, {t}];
ResourceFunction["CumulativeAverages"][td] // ListPlot
Out[14]=

Use an EventSeries object:

In[15]:=
v = {2, 1, 6, 5, 7, 4};
t = {1, 2, 5, 10, 12, 15};
es = EventSeries[v, {t}];
ResourceFunction["CumulativeAverages"][es] // ListPlot
Out[18]=

Neat Examples

Plot the cumulative average of the digits of the ChampernowneNumber:

In[19]:=
digits = N@First[RealDigits[ChampernowneNumber[], 10, 10000]];
cma = ResourceFunction["CumulativeAverages"][digits];
ListLogLinearPlot[cma, PlotRange -> All, Joined -> True]
Out[21]=

Resource History

License Information