forked from pharmaverse/admiral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderive_vars_dy.Rd
90 lines (82 loc) · 2.69 KB
/
derive_vars_dy.Rd
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive_vars_dy.R
\name{derive_vars_dy}
\alias{derive_vars_dy}
\title{Derive Relative Day Variables}
\usage{
derive_vars_dy(dataset, reference_date, source_vars)
}
\arguments{
\item{dataset}{Input dataset
The variables specified by the \code{reference_date} and \code{source_vars} arguments are expected to be in the dataset.}
\item{reference_date}{A date or date-time column, e.g., date of first treatment
or date-time of last exposure to treatment.
Refer to \code{derive_vars_dt()} to impute and derive a date from a date
character vector to a date object.}
\item{source_vars}{A list of datetime or date variables created using
\code{exprs()} from which dates are to be extracted. This can either be a list of
date(time) variables or named \code{--DY} variables and corresponding --DT(M)
variables e.g. \code{exprs(TRTSDTM, ASTDTM, AENDT)} or \code{exprs(TRTSDT, ASTDTM, AENDT, DEATHDY = DTHDT)}. If the source variable does not end in --DT(M), a
name for the resulting \code{--DY} variable must be provided.}
}
\value{
The input dataset with \code{--DY} corresponding to the \code{--DTM} or \code{--DT}
source variable(s) added
}
\description{
Adds relative day variables (\code{--DY}) to the dataset, e.g., \code{ASTDY} and
\code{AENDY}.
}
\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.
}
\examples{
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)
)
}
\seealso{
Date/Time Derivation Functions that returns variable appended to dataset:
\code{\link{derive_var_trtdurd}()},
\code{\link{derive_vars_dt}()},
\code{\link{derive_vars_dtm}()},
\code{\link{derive_vars_dtm_to_dt}()},
\code{\link{derive_vars_dtm_to_tm}()},
\code{\link{derive_vars_duration}()}
}
\concept{der_date_time}
\keyword{der_date_time}
\keyword{der_gen}