Utilizes the DY method from the SDTM spec: --DTC-RFSTDTC+1
if --DTC
is on
or after RFSTDTC. --DTC-RFSTDTC
if --DTC
precedes RFSTDTC
. This
function can also be used for the ENDY method from the spec which has the
same logic.
Arguments
- tbl
a data frame with the date column
RFSTDTC
and the column specified by theDTC_col
argument- DY_col
string, the name of the new DY column to create
- DTC_col
string, the column in
tbl
which has the dates for which to calculated the DY value; should either already have a date class or be a character vector in the format YYYY-MM-DD- RFSTDTC
a string, the column to use for
RFSTDTC
, default is"RFSTDTC"
; should either already have a date class or be a character vector in the format YYYY-MM-DD
Examples
df <- data.frame(
DTC = c("2023-08-01", "2023-08-02", "2023-08-03", "2023-08-04"),
RFSTDTC = rep("2023-08-02", 4)
)
calc_DY(df, DY_col = "XXDY", DTC_col = "DTC")
#> DTC RFSTDTC XXDY
#> 1 2023-08-01 2023-08-02 -1
#> 2 2023-08-02 2023-08-02 1
#> 3 2023-08-03 2023-08-02 2
#> 4 2023-08-04 2023-08-02 3