R/year.R

#' Generate Random Vector of Years
#'
#' Generate a random vector of years.
#'
#' @inheritParams r_sample_factor
#' @return Returns a random vector of year elements.
#' @keywords year
#' @export
#' @include utils.R r_sample.R
#' @family variable functions
#' @examples
#' year(10)
#' pr <- probs(length(1996:2016))
#' pie(table(year(10000, x= 1996:2016, prob = pr)))
year <-function (n, x = 1996:as.numeric(format(Sys.Date(), "%Y")), prob = NULL,
    name = "Year") {

    if (missing(n)) stop("`n` is missing")
    out <- sample(x = x, size = n, replace = TRUE, prob = prob)
    varname(out, name)

}

Try the wakefield package in your browser

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

wakefield documentation built on Sept. 14, 2020, 1:07 a.m.