import copy


def average(values, output, parameter):
    """Aggregator that calculates the average value for each key.

    The result contains all keys that some inputs contain. Each value is an
    average value of the corresponding key through all the inputs. If there
    is a value that cannot be passed to ``float()``, it omits the corresponding
    key from the result.

    """
    scheme = copy.deepcopy(values[0])
    for key in scheme:
        try:
            scheme[key] = sum(
                float(v[key]) for v in values) / float(len(values))
        except:
            pass
    return scheme