Learn R Programming

nprcgenekeepr (version 3.0.0)

chooseDate: Choose the earlier or later of two dates

Description

Part of Pedigree Curation

Usage

chooseDate(d1, d2, earlier = TRUE)

Value

A single Date value, the chosen date, or NA where neither is provided. Vectors longer than one are not supported; use pmin or pmax, or mapply, for vectors.

Arguments

d1

single Date value, the first of two dates to compare.

d2

single Date value, the second of two dates to compare.

earlier

logical variable with TRUE if the earlier of the two dates is to be returned, otherwise the later is returned. Default is TRUE.

Details

Given two dates, one is selected to be returned based on whether it occurred earlier or later than the other. NAs are ignored if possible.

Examples

Run this code
library(nprcgenekeepr)
someDates <- lubridate::mdy(paste0(
  sample(1:12, 2, replace = TRUE), "-",
  sample(1:28, 2, replace = TRUE), "-",
  sample(seq(0, 15, by = 3), 2,
    replace = TRUE
  ) + 2000
))
someDates
chooseDate(someDates[1], someDates[2], earlier = TRUE)
chooseDate(someDates[1], someDates[2], earlier = FALSE)

Run the code above in your browser using DataLab