date_near | R Documentation |
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
date_near(dates, target, thresh = Inf, onlypre = F, sidepref, quiet = T)
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 |
Date object representing closest match to target Date object
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.