Skip to contents

medianNorm normalizes the columns of a matrix by either the median or the mean.

Usage

medianNorm(x, method = "median")

Arguments

x

A numeric matrix to be normalized.

method

A character string specifying the normalization method. Options are "median" or "mean". Default is "median".

Value

A numeric matrix with normalized columns.

Details

The function performs the following steps:

  1. If the method is "median", it calculates the median of each column and adjusts by the overall median of these medians.

  2. If the method is "mean", it calculates the mean of each column and adjusts by the overall mean of these means.

  3. 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