Returns k-quantile of the data. - Java java.lang

Java examples for java.lang:Math Function

Description

Returns k-quantile of the data.

Demo Code


//package com.java2s;
import java.util.Arrays;

public class Main {
    /**// w  w  w  .  j a v a2s.com
     * Returns k-quantile of the data.
     * 
     * @param data
     * @param k in (0,1) is the Quantile we want to use.
     * @return k-quantile of the data
     */
    public static double quantile(double[] data, double k) {
        Arrays.sort(data);
        k = k * data.length;
        return data[(int) Math.ceil(k) - 1];
    }
}

Related Tutorials