Learn R Programming

ds4psy (version 0.2.0)

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

Description

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

Usage

sample_dates(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_dates draws n = 1 random date in the range from = "1970-01-01" to = Sys.Date() (current date).

See Also

Other random functions: coin(), dice_2(), dice(), sample_times()

Examples

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

# Note: Oddity with sample():
sort(sample_dates(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