Description Usage Arguments Details Author(s) Examples
View source: R/derive_var_basetype.R
Adds the BASETYPE
variable to a dataset and duplicates records based upon
the provided conditions
1 | derive_var_basetype(dataset, basetypes)
|
dataset |
Input dataset The columns specified in the expressions inside |
basetypes |
A named list of expressions created using the
The names corresponds to the values of the newly created |
For each element of basetypes
the input dataset is subset based upon
the provided expression and the BASETYPE
variable is set to the name of the
expression. Then, all subsets are stacked. Records which do not match any
condition are kept and BASETYPE
is set to NA
.
Thomas Neitmann
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 | bds <- tibble::tribble(
~USUBJID, ~EPOCH, ~PARAMCD, ~ASEQ, ~AVAL,
"P01", "RUN-IN", "PARAM01", 1, 10,
"P01", "RUN-IN", "PARAM01", 2, 9.8,
"P01", "DOUBLE-BLIND", "PARAM01", 3, 9.2,
"P01", "DOUBLE-BLIND", "PARAM01", 4, 10.1,
"P01", "OPEN-LABEL", "PARAM01", 5, 10.4,
"P01", "OPEN-LABEL", "PARAM01", 6, 9.9,
"P02", "RUN-IN", "PARAM01", 1, 12.1,
"P02", "DOUBLE-BLIND", "PARAM01", 2, 10.2,
"P02", "DOUBLE-BLIND", "PARAM01", 3, 10.8,
"P02", "OPEN-LABEL", "PARAM01", 4, 11.4,
"P02", "OPEN-LABEL", "PARAM01", 5, 10.8
)
bds_with_basetype <- derive_var_basetype(
dataset = bds,
basetypes = exprs(
"RUN-IN" = EPOCH %in% c("RUN-IN", "STABILIZATION", "DOUBLE-BLIND", "OPEN-LABEL"),
"DOUBLE-BLIND" = EPOCH %in% c("DOUBLE-BLIND", "OPEN-LABEL"),
"OPEN-LABEL" = EPOCH == "OPEN-LABEL"
)
)
print(bds_with_basetype)
dplyr::count(bds_with_basetype, BASETYPE, name = "Number of Records")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.