@Test public void testMean() { double expResult = 5.5d; double result = SampleStats.mean(values, true); assertEquals(expResult, result, TOL); }
public static double mean(Double[] values, boolean ignoreNaN) { if (values == null || values.length == 0) { return Double.NaN; } else if (values.length == 1) { return values[0]; } double sum = 0.0d; int n = 0; for (Double val : values) { if (val.isNaN()) { if (!ignoreNaN) return Double.NaN; } else { sum += val; n++ ; } } return sum / n; }
SampleStats { public static double mean(Double[] values, boolean ignoreNaN) { if (values == null || values.length == 0) { return Double.NaN; } else if (values.length == 1) { return values[0]; } double sum = 0.0d; int n = 0; for (Double val : values) { if (val.isNaN()) { if (!ignoreNaN) return Double.NaN; } else { sum += val; n++ ; } } return sum / n; } }
SampleStats { public static double mean(Double[] values, boolean ignoreNaN) { if (values == null || values.length == 0) { return Double.NaN; } else if (values.length == 1) { return values[0]; } double sum = 0.0d; int n = 0; for (Double val : values) { if (val.isNaN()) { if (!ignoreNaN) return Double.NaN; } else { sum += val; n++ ; } } return sum / n; }  }
SampleStats { public static double mean(Double[] values, boolean ignoreNaN) { if (values == null || values.length == 0) { return Double.NaN; } else if (values.length == 1) { return values[0]; } double sum = 0.0d; int n = 0; for (Double val : values) { if (val.isNaN()) { if (!ignoreNaN) return Double.NaN; } else { sum += val; n++ ; } } return sum / n; }  static double max(Double[] values, boolean ignoreNaN); static double mean(Double[] values, boolean ignoreNaN); static double min(Double[] values, boolean ignoreNaN); @SuppressWarnings("empty-statement") static double median(Double[] values, boolean ignoreNaN); @SuppressWarnings("empty-statement") static double mode(Double[] values, boolean ignoreNaN); static double range(Double[] values, boolean ignoreNaN); static double variance(Double[] values, boolean ignoreNaN); static double sdev(Double[] values, boolean ignoreNaN); static double sum(Double[] values, boolean ignoreNaN); }
SampleStats { public static double mean(Double[] values, boolean ignoreNaN) { if (values == null || values.length == 0) { return Double.NaN; } else if (values.length == 1) { return values[0]; } double sum = 0.0d; int n = 0; for (Double val : values) { if (val.isNaN()) { if (!ignoreNaN) return Double.NaN; } else { sum += val; n++ ; } } return sum / n; }  static double max(Double[] values, boolean ignoreNaN); static double mean(Double[] values, boolean ignoreNaN); static double min(Double[] values, boolean ignoreNaN); @SuppressWarnings("empty-statement") static double median(Double[] values, boolean ignoreNaN); @SuppressWarnings("empty-statement") static double mode(Double[] values, boolean ignoreNaN); static double range(Double[] values, boolean ignoreNaN); static double variance(Double[] values, boolean ignoreNaN); static double sdev(Double[] values, boolean ignoreNaN); static double sum(Double[] values, boolean ignoreNaN);  }