sample_date: Produce random dates within a particular range of...

Description Usage Arguments Value Examples

Description

Produce random dates within a particular range of possibilities

Usage

1
2
sample_date(year_min, year_max = year_min, month_min = 1, month_max = 12,
  day_min = 1, day_max = 31, n, .p = null_predicate, quiet = FALSE)

Arguments

year_min

Integer. Minimum year (Required)

year_max

Integer. Maximum year

month_min

Integer. Minimum month

month_max

Integer. Maximum month

day_min

Integer. Minimum day

day_max

Integer. Maximum day

n

Integer. Number of permuations to return. (Required)

.p

An optional predicate function taking a year, month, and day as its parameters, and returning TRUE if the date is valid. Allows one to construct complex date restrictions, such as only generating dates that are Mondays, etc.

quiet

Boolean. Display messages when regenerating illegal dates?

Value

A vector of POSIXct values

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set.seed(100)
# Generate random dates within the year 1930
sample_date(1930, n = 5)

# Dates in March 1930
sample_date(1930, month_min = 3, month_max = 3, n = 5)

# Dates between a given range
sample_date(year_min = 1930, year_max = 1931, day_min = 25, day_max = 31, n = 5)

# Use a predicate function to return only Mondays
sample_date(1930, n = 5, .p = is_monday)

mdlincoln/dateSampler documentation built on May 22, 2019, 4:05 p.m.