public static DataSet center(DataSet data){
  DataSet _data=data.copy();
  for (int j=0; j < _data.getNumColumns(); j++) {
    double sum=0.0;
    int n=0;
    for (int i=0; i < _data.getNumRows(); i++) {
      double v=_data.getDouble(i,j);
      if (!Double.isNaN(v)) {
        sum+=v;
        n++;
      }
    }
    double avg=sum / n;
    for (int i=0; i < _data.getNumRows(); i++) {
      _data.setDouble(i,j,_data.getDouble(i,j) - avg);
    }
  }
  return _data;
}

public static DataSet center ( DataSet data ) { DataSet _data = data . copy ( ) ; for ( int j = 0 ; j < _data . getNumColumns ( ) ; j ++ ) { double sum = 0.0 ; int n = 0 ; for ( int i = 0 ; i < _data . getNumRows ( ) ; i ++ ) { double v = _data . getDouble ( i , j ) ; if ( ! Double . isNaN ( v ) ) { sum += v ; n ++ ; } } double avg = sum / n ; for ( int i = 0 ; i < _data . getNumRows ( ) ; i ++ ) { _data . setDouble ( i , j , _data . getDouble ( i , j ) - avg ) ; } } return _data ; }
subtracts the mean of each column from each datum that column .
