View source: R/derive_vars_dy.R
derive_vars_dy | R Documentation |
Adds relative day variables (--DY
) to the dataset, e.g., ASTDY
and
AENDY
.
derive_vars_dy(dataset, reference_date, source_vars)
dataset |
Input dataset The variables specified by the |
reference_date |
A date or date-time column, e.g., date of first treatment or date-time of last exposure to treatment. Refer to |
source_vars |
A list of datetime or date variables created using
|
The relative day is derived as number of days from the reference date to the end date. If it is nonnegative, one is added. I.e., the relative day of the reference date is 1. Unless a name is explicitly specified, the name of the resulting relative day variable is generated from the source variable name by replacing DT (or DTM as appropriate) with DY.
The input dataset with --DY
corresponding to the --DTM
or --DT
source variable(s) added
Date/Time Derivation Functions that returns variable appended to dataset:
derive_var_trtdurd()
,
derive_vars_dt()
,
derive_vars_dtm()
,
derive_vars_dtm_to_dt()
,
derive_vars_dtm_to_tm()
,
derive_vars_duration()
library(tibble)
library(lubridate)
library(dplyr, warn.conflicts = FALSE)
datain <- tribble(
~TRTSDTM, ~ASTDTM, ~AENDT,
"2014-01-17T23:59:59", "2014-01-18T13:09:O9", "2014-01-20"
) %>%
mutate(
TRTSDTM = as_datetime(TRTSDTM),
ASTDTM = as_datetime(ASTDTM),
AENDT = ymd(AENDT)
)
derive_vars_dy(
datain,
reference_date = TRTSDTM,
source_vars = exprs(TRTSDTM, ASTDTM, AENDT)
)
# specifying name of new variables
datain <- tribble(
~TRTSDT, ~DTHDT,
"2014-01-17", "2014-02-01"
) %>%
mutate(
TRTSDT = ymd(TRTSDT),
DTHDT = ymd(DTHDT)
)
derive_vars_dy(
datain,
reference_date = TRTSDT,
source_vars = exprs(TRTSDT, DEATHDY = DTHDT)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.