Normalizes a numeric matrix dividing each row (if rows=TRUE) or column (if rows=FALSE) by their L2 norm. Thus, each row (or column) has unit norm.
Examples
dat <- matrix(rnorm(50),ncol=5,nrow=10)
cosnormX(dat)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.52052548 0.50768215 0.34246093 -0.33101576 -0.49443012
#> [2,] -0.14652804 0.79381468 0.53119300 0.25422535 -0.03989044
#> [3,] 0.21677075 0.07554259 -0.59197766 -0.71061572 0.30313614
#> [4,] 0.56194932 -0.08815004 0.17431695 -0.75487916 -0.27606809
#> [5,] 0.77088910 0.02774875 -0.18482886 -0.16575575 0.58593799
#> [6,] 0.18845708 -0.15921689 0.75203665 0.61099148 0.01625403
#> [7,] 0.61654194 -0.11129243 -0.71211104 0.28971803 -0.12826287
#> [8,] -0.06215042 -0.17944582 -0.23995466 0.02374133 -0.95173244
#> [9,] 0.06756910 -0.32619437 -0.08038939 -0.61302705 0.71187571
#> [10,] 0.37252294 0.16523170 -0.69904592 0.43050287 -0.39990901