rdate: Generate Random Dates, with a similar usage as the r*...

View source: R/rdate.R

rdateR Documentation

Generate Random Dates, with a similar usage as the r* functions

Description

Generates a vector of random dates within a specified range. This function tries to replicate the usage of the r* functions from stats package, such as runif(), rpois(), ...

Usage

rdate(
  x,
  min = paste0(format(Sys.Date(), "%Y"), "-01-01"),
  max = paste0(format(Sys.Date(), "%Y"), "-12-31"),
  sort = FALSE,
  include_hours = FALSE
)

Arguments

x

Integer. Length of the output vector (number of random dates to generate).

min

Date. Optional. The minimum date for the range. Defaults to the 1st of January of the current year.

max

Date. Optional. The maximum date for the range. Defaults to the 31st of December of the current year.

sort

Logical. Should the dates be sorted in ascending order? Default is 'FALSE'.

include_hours

Logical. Should the generated dates include time? Default is 'FALSE' (dates only). this will slow down the function

Value

A vector of random dates of length 'x'.

Examples

# Generate 5 random dates between two specific dates, sorted
rdate(5, min = as.Date("2020-01-01"), max = as.Date("2020-12-31"), sort = TRUE)

# Generate 7 random datetime values (with hours)
rdate(7, include_hours = TRUE)


R.AlphA.Home documentation built on April 3, 2025, 5:53 p.m.