#' @title Mean Normalization Function
#' @description mean_norm is a function to normalize the mean of the data.
#' After applying this function, the data is expected to be 0 mean.
#' @param a : for now it only supports vector and data.frame only
#' @author Suberlin Sinaga
#' @example
#' \dontrun{
#' a <- c(12,3,4,10,15)
#' mean_norm(a)
#' }
#' @export
mean_norm <- function(a, na.rm = FALSE) {
if(na.rm){
a <- a[!is.na(a)]
}
if (inherits(a, "numeric")) {
res <- (a - mean(a))/(max(a) - min(a))
res <- as_amartha(res)
}else if(inherits(a, "data.frame")){
len <- length(a)
res <- a
for (i in 1:length(a)){
if (!is.numeric(a[[i]])) {
res[,i] <- a[,i]
} else{
res[,i] <- (a[,i] - mean(a[,i]))/(max(a[,i])-min(a[,i]))
}
}
res <- as_amartha(res)
}else{
stop('Provide me numeric vector or data.frame only! Factor or character type is not intended to be mean normalized...')
}
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.