title: R: z-score normalization
body: <p>I´d like to z-score normalize each row of a matrix in R. I use the normalize-function which works fine for this purpose:</p>
  
  <pre><code>library(som)
  
  training &lt;- matrix(seq(1:20), ncol = 10)
  training
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]    1    3    5    7    9   11   13   15   17    19
  [2,]    2    4    6    8   10   12   14   16   18    20
  training_zscore &lt;- normalize(training, byrow=TRUE)
  training_zscore
            [,1]      [,2]       [,3]       [,4]       [,5]      [,6]      [,7]      [,8]     [,9]    [,10]
  [1,] -1.486301 -1.156012 -0.8257228 -0.4954337 -0.1651446 0.1651446 0.4954337 0.8257228 1.156012 1.486301
  [2,] -1.486301 -1.156012 -0.8257228 -0.4954337 -0.1651446 0.1651446 0.4954337 0.8257228 1.156012 1.486301
  </code></pre>
  
  <p>Lets assume that I now have another matrix e.g. the following:</p>
  
  <pre><code>validation &lt;- matrix(seq(1:20)*2, ncol = 10)
  validation
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]    2    6   10   14   18   22   26   30   34    38
  [2,]    4    8   12   16   20   24   28   32   36    40
  </code></pre>
  
  <p>I´d also like to z-score transform this new matrix. However the scaling should be identical to the training z-score matrix. How can I achieve this?</p>
  
  <p>If I´d just perform seperate z-score normalization I´d get the following output:</p>
  
  <pre><code>&gt; validation_zscore &lt;- normalize(validation, byrow=TRUE)
  &gt; validation_zscore
            [,1]      [,2]       [,3]       [,4]       [,5]      [,6]      [,7]      [,8]     [,9]    [,10]
  [1,] -1.486301 -1.156012 -0.8257228 -0.4954337 -0.1651446 0.1651446 0.4954337 0.8257228 1.156012 1.486301
  [2,] -1.486301 -1.156012 -0.8257228 -0.4954337 -0.1651446 0.1651446 0.4954337 0.8257228 1.156012 1.486301
  </code></pre>
  
  <p>This is however not what I want e.g. in the training matrix the value "10" was transformed into a z-score of "-0.1651446". This should also be the case in the validation matrix (here 10 was however converted into a z-score of "-0.8257228"):</p>
  
  <p>Thanks for your help!</p>