code: static void columnAverageImpute(double[][] data) throws MissingValueImputationException {
          for (int j = 0; j < data[0].length; j++) {
              int n = 0;
              double sum = 0.0;
  
              for (int i = 0; i < data.length; i++) {
                  if (!Double.isNaN(data[i][j])) {
                      n++;
                      sum += data[i][j];
                  }
              }
  
              if (n == 0) {
                  continue;
              }
  
              if (n < data.length) {
                  double avg = sum / n;
                  for (int i = 0; i < data.length; i++) {
                      if (Double.isNaN(data[i][j])) {
                          data[i][j] = avg;
                      }
                  }
              }
          }
      }
docs: Impute the missing values with column averages.
  @param data data with missing values.
  @throws smile.imputation.MissingValueImputationException