library(lubridate)
library(purrr)
# Dates -> duration in years
calc_duration(
x = mdy(map_chr(sample(1:9, 5), ~ paste0('01/01/199', .x))),
y = mdy(map_chr(sample(1:9, 5), ~ paste0('01/01/200', .x))),
units = 'years'
)
# datetimes -> durations
calc_duration(
x = mdy_hm(map_chr(sample(1:9, 5), ~ paste0('01/01/199', .x, ' 1', .x, ':00'))),
y = mdy_hm(map_chr(sample(1:9, 5), ~ paste0('01/01/200', .x, ' 0', .x, ':00')))
)
# Mixed date classes -> durations
calc_duration(
x = mdy(map_chr(sample(1:9, 5), ~ paste0('01/01/199', .x))),
y = mdy_hm(map_chr(sample(1:9, 5), ~ paste0('01/01/200', .x, ' 0', .x, ':00')))
)
Run the code above in your browser using DataLab