#' Standardization of data
#'
#' This function standardizes the data matrix so that each variable will have mean 0 and std 1
#'
#' @importFrom stats sd
#' @param dat Data matrix with rows are samples, columns are variables.
#' @return A data matrix with each variable having mean 0 and std 1.
#' @export
#' @examples
#' library(TestPMD)
#' data("covid")
#' mtb <- covid$metabolite
#' standsdmu(mtb)
standsdmu <- function(dat){
mudat <- matrix(rep(apply(dat, 2, mean), dim(dat)[1]), nrow = dim(dat)[1], byrow=T)
dat <- as.matrix((dat - mudat))
for (icol in 1:dim(dat)[2]) {
dat[,icol] <- dat[,icol]/stats::sd(dat[,icol])
}
return(dat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.