This vignette features functions that are not covered in other vignettes.
library(actxps)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
The pol_()
family of functions can be used to calculate
policy years, months, quarters, weeks, or any other arbitrary duration.
Each function accepts a vector of dates and a vector of issue dates.
Example: assume a policy was issued on 2022-05-10 and we are interested in calculating various policy duration values at the end of calendar years 2022-2032.
<- ymd("2022-12-31") + years(0:10)
dates
# policy years
pol_yr(dates, "2022-05-10")
#> [1] 1 2 3 4 5 6 7 8 9 10 11
# policy quarters
pol_qtr(dates, "2022-05-10")
#> [1] 3 7 11 15 19 23 27 31 35 39 43
# policy months
pol_mth(dates, "2022-05-10")
#> [1] 8 20 32 44 56 68 80 92 104 116 128
# policy weeks
pol_wk(dates, "2022-05-10")
#> [1] 34 86 139 191 243 295 347 399 452 504 556
The more general pol_interval()
function can be used to
calculate any arbitrary duration. This function has a third argument
where the length of the policy duration can be specified. This argument
must be a period object. See lubridate::period()
for more
information.
# days
pol_interval(dates, "2022-05-10", days(1))
#> [1] 236 601 967 1332 1697 2062 2428 2793 3158 3523 3889
# fortnights
pol_interval(dates, "2022-05-10", weeks(2))
#> [1] 17 43 70 96 122 148 174 200 226 252 278