date_near: Find Nearest Date within Threshold

View source: R/date_near.R

date_nearR Documentation

Find Nearest Date within Threshold

Description

Searches through vector of Dates for nearest match using given criteria according to function arguments.

sidepref must be filled in as 'l' or 'r' to receieve consistent results If sidepref is missing date_near will return one at random

Usage

date_near(dates, target, thresh = Inf, onlypre = F, sidepref, quiet = T)

Arguments

dates

vector of Date objects to search through

target

Date object to find nearest match

thresh

numeric value for threshold for maximum number of days between match

onlypre

logical for right censor of dates

sidepref

character for decision in case left and right side both have minimum distance

Value

Date object representing closest match to target Date object

Examples

x = seq.Date(from = as.Date("2010-01-01"), to = as.Date("2012-01-01"), length.out = 30)
y = as.Date("2011-01-01")
date_near(x,y, sidepref = 'l')
date_near(x,y, sidepref = 'r')
date_near(x,y, thresh = 1)
date_near(x,"2011-01-12", onlypre = T)

Ajfrick/ajfhelpR documentation built on June 30, 2023, 12:56 a.m.