Description Usage Arguments Value Author(s) Examples
Centers the mean/median of each row/column of the given matrix around zero.
1 | center_matrix(x, by = "row", method = "mean", scale = FALSE, verbose = FALSE)
|
x |
a numeric matrix or Matrix object. |
by |
either "row" or "col". Default is "row". |
method |
either "mean" or "median". Default is "mean". |
scale |
logical indicating whether to scale the rows/columns of x, i.e. divide each row/column by the standard deviation of the row/column. Default is FALSE. |
verbose |
suppresses all messages from this function. Default is FALSE. |
A matrix with either mean or median of row/column centered around zero.
Avishay Spitzer
1 2 3 4 5 6 7 8 9 10 11 | # Center the mean of each row around zero
m <- matrix(runif(25, 0, 100), nrow = 5, ncol = 5) # Generate a 5x5 numeric matrix
m <- center_matrix(m, by = "row", method = "mean", scale = FALSE) # Center
all(rowMeans(m) == 0) # TRUE
all(colMeans(m) == 0) # FALSE
# Center the median of each column around zero
m <- matrix(runif(25, 0, 100), nrow = 5, ncol = 5) # Generate a 5x5 numeric matrix
m <- center_matrix(m, by = "col", method = "median", scale = FALSE) # Center
all(apply(m, 1, median) == 0) # FALSE
all(apply(m, 2, median) == 0) # FALSE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.