com.google.cloud.dataflow.sdk.transforms

## Class Mean

- java.lang.Object
- - com.google.cloud.dataflow.sdk.transforms.Mean

    public class Mean
    extends Object

`PTransform`s for computing the arithmetic mean (a.k.a. average) of the elements in a `PCollection`, or the mean of the values associated with each key in a `PCollection` of `KV`s.

Example 1: get the mean of a `PCollection` of `Long`s.

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

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

     PCollection<KV<String, Integer>> input = ...;
     PCollection<KV<String, Double>> meanPerKey =
         input.apply(Mean.<String, Integer>perKey());

### Method Summary

All Methods Static Methods Concrete Methods
`static <NumT extends Number> Combine.Globally<NumT,Double>` `globally()` Returns a `PTransform` that takes an input `PCollection<NumT>` and returns a `PCollection<Double>` whose contents is the mean of the input `PCollection`'s elements, or `0` if there are no elements.
`static <K,NumT extends Number> Combine.PerKey<K,NumT,Double>` `perKey()` Returns a `PTransform` that takes an input `PCollection<KV<K, N>>` and returns a `PCollection<KV<K, Double>>` that contains an output element mapping each distinct key in the input `PCollection` to the mean of the values associated with that key in the input `PCollection`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### globally

    public static <NumT extends Number> Combine.Globally<NumT,Double> globally()

Returns a `PTransform` that takes an input `PCollection<NumT>` and returns a `PCollection<Double>` whose contents is the mean of the input `PCollection`'s elements, or `0` if there are no elements.

Type Parameters:
  `NumT` - the type of the `Number`s being combined

#### perKey

    public static <K,NumT extends Number> Combine.PerKey<K,NumT,Double> perKey()

Returns a `PTransform` that takes an input `PCollection<KV<K, N>>` and returns a `PCollection<KV<K, Double>>` that contains an output element mapping each distinct key in the input `PCollection` to the mean of the values associated with that key in the input `PCollection`.

See `Combine.PerKey` for how this affects timestamps and bucketing.

Type Parameters:
  `K` - the type of the keys
  `NumT` - the type of the `Number`s being combined