Learn R Programming

ds4psy (version 0.4.0)

sample_date: Draw a sample of n random dates (from a given range).

Description

sample_date draws a sample of n random dates from a given range.

Usage

sample_date(n = 1, from = "1970-01-01", to = Sys.Date())

Arguments

n

Number dates to draw. Default: n = 1.

from

Earliest date (as string). Default: from = "1970-01-01".

to

Latest date (as string). Default: to = Sys.Date().

Details

By default, sample_date draws n = 1 random date (as a "Date" object) in the range from = "1970-01-01" to = Sys.Date() (current date).

See Also

Other sampling functions: coin(), dice_2(), dice(), sample_char(), sample_time()

Examples

Run this code
# NOT RUN {
sample_date()
sort(sample_date(n = 10))
sort(sample_date(n = 10, from = "2020-02-28", to = "2020-03-01"))  # 2020 is a leap year

# Note: Oddity with sample():
sort(sample_date(n = 10, from = "2020-01-01", to = "2020-01-01"))  # range of 0!
# see sample(9:9, size = 10, replace = TRUE)

# }

Run the code above in your browser using DataLab