question: 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 ; }
target:  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); 