Here you can find the source of mean(final double[] data, final boolean noNaN)
Parameter | Description |
---|---|
data | Data |
noNaN | true if NaN value must be removed from the computation |
public static double mean(final double[] data, final boolean noNaN)
//package com.java2s; /*//from www . j a v a 2s. co m * Nividic development code * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. If you do not have a copy, * see: * * http://www.gnu.org/copyleft/lesser.html * * Copyright for this code is held jointly by the microarray platform * of the ?cole Normale Sup?rieure and the individual authors. * These should be listed in @author doc comments. * * For more information on the Nividic project and its aims, * or to join the Nividic mailing list, visit the home page * at: * * http://www.transcriptome.ens.fr/nividic * */ public class Main { /** * Calc the mean of an array of double * @param data Data * @param noNaN true if NaN value must be removed from the computation * @return the mean or NaN if the data is null */ public static double mean(final double[] data, final boolean noNaN) { return mean(noNaN ? removeNaN(data) : data); } /** * Calc the mean of an array of double * @param data Data * @return the mean or NaN if the data is null */ public static double mean(final double[] data) { if (data == null) return Double.NaN; int count = 0; float sum = 0; for (int i = 0; i < data.length; i++) { count++; sum += data[i]; } return sum / count; } /** * Remove NaN from an array * @param data Array to use * @return an new array without NaN values */ public static double[] removeNaN(final double[] data) { if (data == null) return null; int count = 0; for (int i = 0; i < data.length; i++) if (Double.isNaN(data[i])) count++; final double[] result = new double[count]; count = 0; for (int i = 0; i < result.length; i++) if (!Double.isNaN(data[i])) result[count++] = data[i]; return result; } }