Java Array Average avgIgnoreNaN(double[] values)

Here you can find the source of avgIgnoreNaN(double[] values)

Description

avg Ignore Na N

License

Open Source License

Declaration

public static double avgIgnoreNaN(double[] values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double avgIgnoreNaN(double[] values) {
        double avg = 0;
        int counter = 0;
        for (double v : values) {
            if (!Double.isNaN(v)) {
                avg += v;/*ww  w  .j a  va 2s  . c o  m*/
                counter++;
            }
        }
        if (counter == 0) {
            return 0;
        }
        return avg / (double) counter;
    }
}

Related

  1. avg(int[] xs)
  2. avg(int[][] values)
  3. avgarr(int[] a)
  4. avgArray(double[] values, int maxLength)
  5. avgArrayAndDouble(double[] array, double doublevalue)
  6. avgOfArray(double[] array)
  7. avgRng(double[] high, double[] low, int days)
  8. getAverage(double[] values)
  9. getAverage(int[] values)