R/RWeights.R

Defines functions RWeights

Documented in RWeights

#' @title Draw random number between 1 and length(weights) with the distribution
#' @param n Number of random numbers to be drawn
#' @param weights vector of numbers; defines the distribution
#' @return vector of n random numbers between 1 and length(weights)
#' @author Thomas Laepple
#' @examples
#' weights <- c(rep(1,10), 1:10, 10:1)
#' hist(RWeights(100000, weights), breaks = 501)
#' @export
RWeights <- function(n = 1000, weights) {
  function_deprecated("stattools")
  base::sample.int(length(weights),
    n,
    prob = weights,
    replace = TRUE
  )
}
EarthSystemDiagnostics/ecustools documentation built on Jan. 15, 2022, 5:22 p.m.