A running average can be either of two measurements. A cumulative running average includes all values, and is updated whenever a new value is added to the data set. Running average may also refer to moving average, or the average of a subset of the most recent measurements.
You might calculate the cumulative running average of the age of everyone in a club. Every time a new member joins, the cumulative average changes. A moving average could be the average high temperature over the last two weeks: each day, the set of data used to calculate the average “moves” one day.
Sum all data values. For example, the sum of the seven numbers 34, 35, 23, 26, 40, 27 and 39 is 224.
Divide the sum of all values by the number of values in the data set to obtain the average value. In the example, the average is 224 / 7 = 32. Store or otherwise remember the sum and the number of values.
Add any newly recorded values to the previous sum of numbers. For a new value = 38 added to the previous data set, the new sum is 262. There are now eight values, so the new average = 262 / 8 = 32.75. Continue adding new values to the previous sum, and continue to increment the count of variables each time.
Select a window size. For example, from a set of seven numbers (34, 35, 23, 26, 40, 27, 39) a reasonable window size could be 5. Sum the 5 most recently recorded numbers: 23 + 26 + 40 + 27 + 39 = 155.
Divide the sum by 5, the number of values in the window. Using the example, 155 / 5 = 31.
Add any new values to the end of the list of numbers, such as a new value of 38. Sum the 5 values most recently recorded, in this case 26 + 40 + 27 + 39 + 38 = 170.
Divide the sum by 5, because the number of values in the window has not changed. In our example, 170 / 5 = 34.
Repeat, each time discarding the oldest value from the window and adding in the newest value. Always divide by the same number, the window "length."
A cumulative running average will always change toward the most recently recorded number. The larger the count of variables, the less a cumulative average will change. A moving average is intended to measure short-term trends. Moving averages are often used when measurements are made at regular time intervals.