#' Clamps all elements in `x` into the range `[min,max]`
#'
#' same functionality as torch.clamp
#'
#' @param x numeric vector
#' @param min minimum value allowed in the returned vector
#' @param max maximum value allowed in the returned vector
#'
#' @return vector like x in the range `[min,max]`
#' @export
#'
#' @examples
#' clamp(seq(-1,2, by=0.25))
clamp <- function(x, min = 0, max = 1){
x = pmax(x, min)
x = pmin(x, max)
return(x)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.