mean
Description
Computes the mean (arithmetic average) of an Observable
.
Examples
Basic Example
API
Since
0.1
Parameters
None
Options
initialState: Object {average: Number, sum: Number, index: Number
: Sets a warm start value so that the mean calculation can continue from a non-zero starting point (instead of a blank state).
Returns
Number
. (The current mean of the Observable
.)
More Examples
Skipping the first value
It's odd to calculate the mean of just one item. Sometimes, it makes more sense to skip the first item to ensure that means are calculated based on more than one number. RxJS makes this easy:
Warm Start
Calculate a mean with an initial warmstart value (instead starting with a blank state):
Using Hotstarts to aggregate multiple streams
Sometimes it is useful to be able to compute a mean from multiple data streams without processing the individual items from each stream. rxstats
enables this too. Suppose you have data points from 3 different users' browser applications. They can be combined into a single mean that represents all three data streams:
In the example above, aggregateMean$
computes the mean of the data points from all three users without viewing any of their individual information!
Last updated