Skip to contents

This function rescales the rows of a matrix according to the specified type.

Usage

rescale_matrix(
  mat,
  type = c("Expression", "Log2 Expression", "Mean Scaled", "Z-score")
)

Arguments

mat

the matrix to rescale

type

type of rescaling; one of "Expression" (defautl, does nothing), "Log2 Expression" (returns log2(x + 1) for every value), "Mean Scaled" (each row is scaled by its average), "Z-score" (each row is centered and scaled to mean = 0 and sd = 1)

Value

The rescaled matrix.

Examples

mat = matrix(1:10, nrow = 2, ncol = 5)
rescale_matrix(mat, type = "Expression")
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    3    5    7    9
#> [2,]    2    4    6    8   10
rescale_matrix(mat, type = "Log2 Expression")
#>          [,1]     [,2]     [,3]     [,4]     [,5]
#> [1,] 1.000000 2.000000 2.584963 3.000000 3.321928
#> [2,] 1.584963 2.321928 2.807355 3.169925 3.459432
rescale_matrix(mat, type = "Mean Scaled")
#>           [,1]      [,2] [,3]     [,4]     [,5]
#> [1,] 0.2000000 0.6000000    1 1.400000 1.800000
#> [2,] 0.3333333 0.6666667    1 1.333333 1.666667
rescale_matrix(mat, type = "Z-score")
#>           [,1]       [,2] [,3]      [,4]     [,5]
#> [1,] -1.264911 -0.6324555    0 0.6324555 1.264911
#> [2,] -1.264911 -0.6324555    0 0.6324555 1.264911
#> attr(,"scaled:center")
#> [1] 5 6
#> attr(,"scaled:scale")
#> [1] 3.162278 3.162278