/// <summary> /// Estimates the sample mean. /// Returns NaN if data is empty or if any entry is NaN. /// </summary> /// <param name="data">The data to calculate the mean of.</param> /// <returns>The mean of the sample.</returns> public static double Mean(this IEnumerable <double> data) { var array = data as double[]; return(array != null ? ArrayStatistics.Mean(array) : StreamingStatistics.Mean(data)); }
/// <summary> /// Estimates the sample mean. /// Returns NaN if data is empty or if any entry is NaN. /// Null-entries are ignored. /// </summary> /// <param name="data">The data to calculate the mean of.</param> /// <returns>The mean of the sample.</returns> public static double Mean(this IEnumerable <double?> data) { if (data == null) { throw new ArgumentNullException("data"); } return(StreamingStatistics.Mean(data.Where(d => d.HasValue).Select(d => d.Value))); }
/// <summary> /// Estimates the sample mean. /// Returns NaN if data is empty or if any entry is NaN. /// Null-entries are ignored. /// </summary> /// <param name="data">The data to calculate the mean of.</param> /// <returns>The mean of the sample.</returns> public static double Mean(this IEnumerable <double?> data) { return(StreamingStatistics.Mean(data.Where(d => d.HasValue).Select(d => d.Value))); }