d <- data.frame(
s1 = c(as.Date("2013-01-01") + 0:10, as.Date(c("2012-01-01", "2014-01-01"))),
s2 = c(as.Date("2013-02-01") + 0:10, as.Date(c("2012-01-01", "2014-01-01"))),
s3 = c(as.Date("2013-01-10") - 0:10, as.Date(c("2012-01-01", "2014-01-01"))),
ps = as.Date("2012-12-31"),
pe = as.Date("2013-01-09")
)
print(dd <- find_date_cause(d, s1, s2, s3, period_start = ps, period_end = pe))
print(bb <- find_date_cause(d, s1, s2, s3, period_start = ps, period_end = pe,
na_fill = "end",
datecol = "enddate",
datereason = "endcause"))
find_date_cause(d, s3, s2, s1, period_start = ps, period_end = pe)
# works
assert_positive_timespan(dd, start_date, pe)
# returns a warning because the last date isn't later than the start_date
assert_positive_timespan(dd, start_date, s2)
with(d, constrain_dates(s1, ps, pe))
with(d, constrain_dates(s2, ps, pe))
with(d, constrain_dates(s3, ps, pe))
Run the code above in your browser using DataLab