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.449490 3.265986 2.449490 3.265986 0.8164966
#> [2,] 3.651484 3.651484 4.564355 1.825742 3.6514837
#> [3,] 5.976143 5.976143 4.780914 3.585686 4.7809144
#> [4,] 1.025978 2.564946 2.564946 2.564946 0.5129892
#> attr(,"scaled:scale")
#> [1] 1.224745 1.095445 0.836660 1.949359
normalize(x, 2) # normalizing columns
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 2.323790 6.928203 3.133398 3.098387 0.5773503
#> [2,] 3.098387 6.928203 5.222330 1.549193 2.3094011
#> [3,] 3.872983 8.660254 4.177864 2.323790 2.3094011
#> [4,] 1.549193 8.660254 5.222330 3.872983 0.5773503
#> attr(,"scaled:scale")
#> [1] 1.2909944 0.5773503 0.9574271 1.2909944 1.7320508