derive_vars_dy: Derive Relative Day Variables

Description Usage Arguments Details Value Author(s) Examples

View source: R/derive_vars_dy.R

Description

Adds relative day variables (--DY) to the dataset, e.g., ASTDY and AENDY.

Usage

1
derive_vars_dy(dataset, reference_date, source_vars)

Arguments

dataset

Input dataset

The columns specified by the reference_date and the source_vars parameter are expected.

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 vars() from which dates are to be extracted. This can either be a list of date(time) variables or named --DY variables and corresponding –DT(M) variables e.g. vars(TRTSDTM, ASTDTM, AENDT) or vars(TRTSDT, ASTDTM, AENDT, DEATHDY = DTHDT). If the source variable does not end in –DT(M), a name for the resulting --DY variable must be provided.

Details

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.

Value

The input dataset with --DY corresponding to the --DTM or --DT source variable(s) added

Author(s)

Teckla Akinyi

Examples

 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))

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.