#' @title Laveling around zero
#'
#' @description Make 3 labels: 1, 0, -1, where 0 are returns closest to zero
#'
#' @param x returns
#'
#' @return factor vector of labels
#'
#' @export
labeling_around_zero <- function(x) {
x_abs <- abs(x)
bin <- cut(x_abs, quantile(x_abs, probs = c(0, 0.3333)), labels = 0L, include.lowest = TRUE)
max_0 <- max(x[bin == 0], na.rm = TRUE)
min_0 <- min(x[bin == 0], na.rm = TRUE)
levels(bin) <- c(levels(bin), 1L, -1L)
bin[x > max_0] <- as.character(1L)
bin[x < min_0] <- as.factor(-1)
return(bin)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.