Javadoc Javadoc

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.


Example 1: get the mean of a PCollection of Longs.

PCollection<Double> input = ...;
PCollection<Double> mean = input.apply(Mean.globally());

Example 2: calculate the mean of the Integers associated with each unique key (which is of type String).

PCollection<KV<String, Integer>> input = ...;
PCollection<KV<String, Integer>> meanPerKey =