forked from pharmaverse/admiral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderive_vars_dtm_to_tm.Rd
68 lines (63 loc) · 2.24 KB
/
derive_vars_dtm_to_tm.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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/derive_vars_dtm_to_tm.R
\name{derive_vars_dtm_to_tm}
\alias{derive_vars_dtm_to_tm}
\title{Derive Time Variables from Datetime Variables}
\usage{
derive_vars_dtm_to_tm(dataset, source_vars)
}
\arguments{
\item{dataset}{Input dataset
The variables specified by the \code{source_vars} argument are expected to be in the dataset.}
\item{source_vars}{A list of datetime variables created using \code{exprs()} from
which time is to be extracted}
}
\value{
A data frame containing the input dataset with the corresponding time
(\code{--TM}) variable(s) of all datetime variables (\code{--DTM}) specified in
\code{source_vars} with the correct name.
}
\description{
This function creates time variable(s) as output from datetime variable(s)
}
\details{
The names of the newly added variables are automatically set by replacing the
\code{--DTM} suffix of the \code{source_vars} with \code{--TM}. The \code{--TM} variables are created
using the \code{{hms}} package.
}
\examples{
library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(lubridate)
adcm <- tribble(
~USUBJID, ~TRTSDTM, ~ASTDTM, ~AENDTM,
"PAT01", "2012-02-25 23:41:10", "2012-02-28 19:03:00", "2013-02-25 23:32:16",
"PAT01", "", "2012-02-28 19:00:00", "",
"PAT01", "2017-02-25 23:00:02", "2013-02-25 19:00:15", "2014-02-25 19:00:56",
"PAT01", "2017-02-25 16:00:00", "2017-02-25 14:25:00", "2017-03-25 23:00:00",
"PAT01", "2017-02-25 16:05:17", "2017-02-25 14:20:00", "2018-04-29 14:06:45",
) \%>\%
mutate(
TRTSDTM = as_datetime(TRTSDTM),
ASTDTM = as_datetime(ASTDTM),
AENDTM = as_datetime(AENDTM)
)
adcm \%>\%
derive_vars_dtm_to_tm(exprs(TRTSDTM)) \%>\%
select(USUBJID, starts_with("TRT"), everything())
adcm \%>\%
derive_vars_dtm_to_tm(exprs(TRTSDTM, ASTDTM, AENDTM)) \%>\%
select(USUBJID, starts_with("TRT"), starts_with("AS"), starts_with("AE"))
}
\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_duration}()},
\code{\link{derive_vars_dy}()}
}
\concept{der_date_time}
\keyword{der_date_time}
\keyword{der_gen}