I give myself very good advice, but I very seldom follow it.

apply() function

,

Data

This is the value of matrix a

The mean of a’s rows

The stddev of a’s rows

z-score conversion

z0 function is defined to normalize a vector against its own mean and stddev

z1 function is defined to normalize a vector against another mean and stddev

Applying z0() along the rows of a gives

Applying z0() along the columns of a gives

The result of apply() along the row (axis=1) of the matrix is transposed since each operation return a column vector, and these vectors are cbind to give the final matrix.

Applying z1() with precalculated mean and sd gives