#' Scaling robust against outliers
#' @param x vector of values
#' @param trunc percentile of values not to take into account for calculating scaling-pameters
#' @return scaled vector of values
#' @export
scale_robust <- function(x, trunc = .05){
N <- length(x)
x_normal <- sort(x)[round(trunc * N) : round((1 - trunc) * N)]
x.robustscaled <- (x - mean(x_normal)) / sd(x_normal)
# if no variance, return NAs
if(sd(x_normal) == 0) return(rep(NA, N))
return(x.robustscaled)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.