#' Function to discretize a variable based on a selected quantile
#'
#' @param x variable to discretize
#' @param q probability corresponding to quantile
#'
#' @return \code{vector} with a discretized version of x.
#'
#' @examples
#'
#' x <- runif(100,-1,1)
#' y <- x^2 + rnorm(100)
#'
#' summary( lm(y ~ Q(x,0.25) ) )
#' summary( lm(y ~ Q(x,0.75) ) )
#'
#' @export
Q <- function(x,q){
q_ <- quantile(x,probs=q)
return(as.numeric(x > q_))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.