public static Double calculateAverage(List<Double> list){
  double sum=0;
  long N=0;
  if (!list.isEmpty()) {
    for (    Double z : list) {
      if (z != null && !Double.isNaN(z)) {
        sum+=z;
        N++;
      }
    }
    return (double)sum / N;
  }
  return Double.NaN;
}

public static Double calculateAverage ( List < Double > list ) { double sum = 0 ; long N = 0 ; if ( ! list . isEmpty ( ) ) { for ( Double z : list ) { if ( z != null && ! Double . isNaN ( z ) ) { sum += z ; N ++ ; } } return ( double ) sum / N ; } return Double . NaN ; }
average of ints in array x . adapted from : http : / / stackoverflow . com / questions / 10791568 / calculating - average - of - an - array - list null values are ignored , like r mean ( . . . , na . rm = true ) . returns float . nan if input list is empty or only nulls . you can check for float . nan with float . isnan ( x ) ;
