Normalize rows or columns by its standard deviation.
Examples
x <- matrix(sample(1:5, 20, rep = TRUE), 4)
normalize(x, 1) # normalizing rows
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 2.828427 2.8284271 1.414214 2.828427 4.2426407
#> [2,] 3.162278 2.5298221 1.264911 1.897367 0.6324555
#> [3,] 3.042903 3.0429031 1.217161 1.217161 3.0429031
#> [4,] 1.264911 0.6324555 1.897367 2.529822 3.1622777
#> attr(,"scaled:scale")
#> [1] 0.7071068 1.5811388 1.6431677 1.5811388
normalize(x, 2) # normalizing columns
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.154701 1.0954451 1.224745 2.088932 1.566699
#> [2,] 2.886751 2.1908902 2.449490 3.133398 0.522233
#> [3,] 2.886751 2.7386128 2.449490 2.088932 2.611165
#> [4,] 1.154701 0.5477226 3.674235 4.177864 2.611165
#> attr(,"scaled:scale")
#> [1] 1.7320508 1.8257419 0.8164966 0.9574271 1.9148542