Mean
Transforms for computing the arithmetic mean of the elements in a collection, or the mean of the values associated with each key in a collection of key-value pairs.
Mean.globally()
returns a transform that then returns a collection whose contents is the mean of the input collection’s elements. If there are no elements in the input collection, it returns 0.Mean.perKey()
returns a transform that returns a collection that contains an output element mapping each distinct key in the input collection to the mean of the values associated with that key in the input collection.
Examples
Example 1: get the mean of a PCollection
of Longs
.
Example 2: calculate the mean of the Integers
associated with each unique key (which is of type String
).
Related transforms
- Max for computing maximum values in a collection
- Min for computing maximum values in a collection
- Combine for combining all values associated with a key to a single result
Last updated on 2024/10/05
Have you found everything you were looking for?
Was it all useful and clear? Is there anything that you would like to change? Let us know!