derive_vars_aage {admiral} | R Documentation |
Derives analysis age (AAGE
) and analysis age unit (AAGEU
).
Note: This is a wrapper function for the more generic derive_vars_duration()
.
derive_vars_aage(
dataset,
start_date = BRTHDT,
end_date = RANDDT,
unit = "years",
age_unit = "years",
type = "interval"
)
dataset |
Input dataset The columns specified by the |
start_date |
The start date A date or date-time object is expected. Refer to Default: |
end_date |
The end date A date or date-time object is expected. Refer to Default: |
unit |
Deprecated, please use |
age_unit |
Age unit The age is derived in the specified unit Default: 'years' Permitted Values: 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds' |
type |
lubridate duration type. See below for details. Permitted Values: |
The duration is derived as time from start to end date in the specified output unit. If the end date is before the start date, the duration is negative. The start and end date variable must be present in the specified input dataset.
The lubridate package calculates two types of spans between two dates: duration and interval. While these calculations are largely the same, when the unit of the time period is month or year the result can be slightly different.
The difference arises from the ambiguity in the length of "1 month"
or
"1 year"
.
Months may have 31, 30, 28, or 29 days, and years are 365 days and 366 during leap years.
Durations and intervals help solve the ambiguity in these measures.
The interval between 2000-02-01
and 2000-03-01
is 1
(i.e. one month).
The duration between these two dates is 0.95
, which accounts for the fact
that the year 2000 is a leap year, February has 29 days, and the average month
length is 30.4375
, i.e. 29 / 30.4375 = 0.95
.
For additional details, review the lubridate time span reference page.
The input dataset with AAGE
and AAGEU
added
ADSL Functions that returns variable appended to dataset:
derive_var_age_years()
,
derive_var_dthcaus()
,
derive_var_extreme_dtm()
,
derive_var_extreme_dt()
,
derive_vars_period()
library(tibble)
library(lubridate)
data <- tribble(
~BRTHDT, ~RANDDT,
ymd("1984-09-06"), ymd("2020-02-24")
)
derive_vars_aage(data)