public static Double getMedian(Dataset instances, Integer index) {
        ArrayList<Double> list = new ArrayList<Double>();
        for (Instance instance: instances) {
            list.add(instance.get(index));
        }
        Collections.sort(list);
        Double median = list.get(list.size() / 2);
        if ((median - list.get(list.size() - 1) < 0.001) && (median - list.get(0) > 0.001)) {
            Integer lIndex = list.size() / 2;
            --lIndex;
            while ((lIndex != 0) && (median - list.get(lIndex) < 0.001)) {
                --lIndex;
            }
            median = list.get(lIndex);
        }

        return median;
    }