
Last chance! 50% off unlimited learning
Sale ends in
sample_date
draws a sample of
n
random dates from a given range.
sample_date(from = "1970-01-01", to = Sys.Date(), size = 1, ...)
Earliest date (as "Date" or string).
Default: from = "1970-01-01"
(as a scalar).
Latest date (as "Date" or string).
Default: to = Sys.Date()
(as a scalar).
Size of date samples to draw.
Default: size = 1
.
Other arguments.
(Use for specifying replace
, as passed to sample()
.)
A vector of class "Date".
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).
Both from
and to
currently
need to be scalars (i.e., with a length of 1).
Other sampling functions:
coin()
,
dice_2()
,
dice()
,
sample_char()
,
sample_time()
# NOT RUN {
sample_date()
sort(sample_date(size = 10))
sort(sample_date(from = "2020-02-28", to = "2020-03-01",
size = 10, replace = TRUE)) # 2020 is a leap year
# Note: Oddity with sample():
sort(sample_date(from = "2020-01-01", to = "2020-01-01", size = 10, replace = TRUE)) # range of 0!
# see sample(9:9, size = 10, replace = TRUE)
# }
Run the code above in your browser using DataLab