Description Usage Arguments Details Value Author(s) Examples
View source: R/derive_vars_dy.R
Adds relative day variables (--DY
) to the dataset, e.g., ASTDY
and
AENDY
.
1 | derive_vars_dy(dataset, reference_date, source_vars)
|
dataset |
Input dataset The columns specified by the |
reference_date |
The start date column, e.g., date of first treatment A date or date-time object column is expected. |
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
Teckla Akinyi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | library(lubridate)
library(dplyr)
datain <- tibble::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 = vars(TRTSDTM, ASTDTM, AENDT))
# specifying name of new variables
datain <- tibble::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 = vars(TRTSDT, DEATHDY = DTHDT))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.