R/sample_safe.R

Defines functions sample_safe

Documented in sample_safe

#' Safe sampling
#'
#' Safely extracts a random unitary sample from a vector.
#' @param x Vector.
#' @return Random sample.
#' @examples 
#'intake <- DIETCOST::sample_safe(c(10,25,37,52,100));
#' @export
sample_safe <- function(x) {
  if (length(x) <= 1) {
    return(x)
  } else {
    return(sample(x,1))
  }
}

Try the DIETCOST package in your browser

Any scripts or data that you put into this service are public.

DIETCOST documentation built on June 8, 2025, 1:51 p.m.