operate_within: Proportion of day pairs within a tolerance

operate_withinR Documentation

Proportion of day pairs within a tolerance

Description

date_by_intersecting() is the proportion that goes with date_is_intersecting(). For each pair of values, it gives the share of pairs of compatible days, one from x[i] and one from y[i], that are at most within days apart. If the two true dates are independent, and each is equally likely to be any of its compatible days, this is the probability that they are within within days of each other. It is 1 when every pair is within the tolerance (a certain match), between 0 and 1 when some are (a possible match), and 0 when none is.

Usage

date_by_intersecting(x, y, within = 0, approx_range = 0)

Arguments

x, y

mdate or other class objects

within

A tolerance in days, 0 or more. Two dates intersect within within days if one of the days of x and one of the days of y are at most within days apart. The tolerance applies to every date, after any widening by approx_range. A time of day is ignored, and dates before the common era give NA when within is above 0.

approx_range

Range to widen approximate values (~ or ⁠%⁠) by before the test, as in compatible_dates(). 0 (the default) ignores the marks.

Details

With approx_range above 0, an approximate value (~ or ⁠%⁠) widens as in compatible_dates(), and each of its days counts by the trapezoidal weight that vrandom() uses, so that the share is a weighted share. Days, months, years and ranges of common-era dates are computed from their first and last days, without a list of days. Other values (sets, unspecified digits, open ranges) list their days. A missing value gives NA, and the empty set, {}, gives 0. A time of day is ignored, and dates before the common era give NA when within is above 0.

Value

A numeric vector of proportions between 0 and 1, of the common length of x and y.

Examples

# an exact day against a week-long range, and within a day of it
x <- as_messydate("2001-05-13..2001-05-19")
date_by_intersecting(x, as_messydate("2001-05-16"))
date_by_intersecting(x, as_messydate("2001-05-16"), within = 1)
# an approximate date, widened by three days with trapezoidal weights
date_by_intersecting(as_messydate("2001-05-16~"), as_messydate("2001-05-18"),
  within = 1, approx_range = 3)

messydates documentation built on Dec. 3, 2026, 5:09 p.m.