Beispiel #1
0
 public static double[] columnMeansNoNA(double[] x, int nrow, int ncol) {
     double[] res = new double[ncol];
     for (int j = 0; j < ncol; j++) {
         int offset = j * nrow;
         double sum = 0;
         for (int k = 0; k < nrow; k++) {
             sum += x[offset + k];
         }
         double tmp = sum / nrow;
         if (RDouble.RDoubleUtils.isFinite(tmp)) {
             sum = 0;
             for (int k = 0; k < nrow; k++) {
                 sum += x[offset + k] - tmp;
             }
             tmp += sum / nrow;
         }
         res[j] = tmp;
     }
     return res;
 }
Beispiel #2
0
 public static double[] columnMeans(double[] x, int nrow, int ncol, boolean[] hasNA) {
     double[] res = new double[ncol];
     for (int j = 0; j < ncol; j++) {
         if (hasNA[j]) {
             res[j] = RDouble.NA;
             continue;
         }
         int offset = j * nrow;
         double sum = 0;
         for (int k = 0; k < nrow; k++) {
             sum += x[offset + k];
         }
         double tmp = sum / nrow;
         if (RDouble.RDoubleUtils.isFinite(tmp)) {
             sum = 0;
             for (int k = 0; k < nrow; k++) {
                 sum += x[offset + k] - tmp;
             }
             tmp += sum / nrow;
         }
         res[j] = tmp;
     }
     return res;
 }