R/fasterscale.R

#' @title Faster version for scale function
#' 
#' @description Does the thing as \code{scale()} but faster.
#' @details Uses colSds() from \code{matrixStats} package.
#' @param x A matrix; \code{is.matrix(x)} should be \code{TRUE}.
#' @return A matrix in which columns are centered to have zero mean and scaled to have sd one.
#' @importFrom matrixStats colSds
#' @export
scalefaster <- function (x) {
	a <- colMeans(x)
	b <- colSds(x)
	x <- t(t(x) - a)
	x <- t(t(x) / b)
	return(x)
}
Zepeng-Mu/fasterscale documentation built on Jan. 23, 2020, 12:20 a.m.