medianNorm
normalizes the columns of a matrix by either the median or
the mean.
Details
The function performs the following steps:
If the
method
is "median", it calculates the median of each column and adjusts by the overall median of these medians.If the
method
is "mean", it calculates the mean of each column and adjusts by the overall mean of these means.It constructs a matrix of these adjusted values and subtracts it from the original matrix to normalize the columns.
Examples
# Example usage:
x <- matrix(rnorm(20), nrow=5, ncol=4)
medianNorm(x, method = "median")
#> [,1] [,2] [,3] [,4]
#> [1,] -0.098410078 0.51062901 -0.01521157 -0.01521157
#> [2,] 1.187034945 -1.52672049 -0.45850424 0.08240034
#> [3,] -0.630927856 1.38920698 1.54749453 1.52052073
#> [4,] 0.009277437 -1.06502852 0.93883174 -0.29261327
#> [5,] -0.015211574 -0.01521157 -0.17083951 -0.65746550