public static double mean(double[] data,int[] inds){
  double mean=0;
  for (int i=0; i < inds.length; i++) {
    if (Double.isNaN(data[inds[i]]))     throw new IllegalArgumentException("NaN not allowed in mean calculation");
    mean+=data[inds[i]];
  }
  mean/=inds.length;
  return mean;
}

public static double mean ( double [ ] data , int [ ] inds ) { double mean = 0 ; for ( int i = 0 ; i < inds . length ; i ++ ) { if ( Double . isNaN ( data [ inds [ i ] ] ) ) throw new IllegalArgumentException ( "NaN not allowed in mean calculation" ) ; mean += data [ inds [ i ] ] ; } mean /= inds . length ; return mean ; }
compute the mean of all elements in the array with given indices . no missing values ( nan ) are allowed .
