# standardization =======================================
#' Safe centering and scaling: it avoids dividing by 0
#' @param x matrix to center and scale
#' @param center either numeric vector or logical
#' @param scale either numeric vector or logical.
#' If numeric, the 0 entries are internally replaced by 1
#' to avoid dividing by zero.
#' @return centred and scaled matrix
#' @export
zscore <- function(x, center = TRUE, scale = TRUE) {
x = as.matrix(x)
if ( isTRUE(scale) ) {
scale = matrixStats::colSds(x)
}
if ( !is.logical(scale) ) {
scale[scale == 0] = 1
}
base::scale(x, center = center, scale = scale)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.