View source: R/derive_vars_aage.R
derive_vars_aage | 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,
age_unit = "YEARS",
type = "interval"
)
dataset |
Input dataset The variables 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: |
age_unit |
Age unit The age is derived in the specified unit Permitted Values (case-insensitive): For years: For months: For weeks: For days: For hours: For minutes: For seconds: |
type |
lubridate duration type. See below for details. Default: 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
derive_vars_duration()
ADSL Functions that returns variable appended to dataset:
derive_var_age_years()
,
derive_vars_extreme_event()
,
derive_vars_period()
library(tibble)
library(lubridate)
data <- tribble(
~BRTHDT, ~RANDDT,
ymd("1984-09-06"), ymd("2020-02-24")
)
derive_vars_aage(data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.