STK++ 0.9.13
Tips: Compute the mean for each column of an array

You can easily get the mean of a whole vector or a matrix containing missing values using the expression.

CArray<Real> A(100, 20);
Law::Normal law(1,2);
A.rand(law);
Real m = A.meanSafe();

In some cases you may want to get the mean for each column of an array with missing values. You can get it in a PointX vector using either the code

PointX m;
m = meanByCol(A.safe()); // mean(A.safe()); work too

or the code

Array2DPoint<Real> m;
m.move(Stat::mean(A.safe()));

The method A.safe() will replace any missing (or NaN) values by zero. In some cases it's not sufficient, Suppose you know your data are all positive and you want to compute the log-mean of your data. In this case, you will rather use

m = Stat::mean(A.safe(1.).log());

and all missing (or NaN) values will be replaced by one.

Note
You can also compute the variance. If you want to compute the mean of each row, you will have to use the functor Stat::meanByRow. In this latter case, VectorX as a result.
See also
STK::Stat::mean, STK::Stat::meanByRow, STK::Stat::variance, STK::Stat::varianceByRow, STK::Stat::varianceWithFixedMean