derive_var_basetype: Derive BASETYPE Variable

Description Usage Arguments Details Author(s) Examples

View source: R/derive_var_basetype.R

Description

Adds the BASETYPE variable to a dataset and duplicates records based upon the provided conditions

Usage

1
derive_var_basetype(dataset, basetypes)

Arguments

dataset

Input dataset

The columns specified in the expressions inside basetypes are required.

basetypes

A named list of expressions created using the exprs function

The names corresponds to the values of the newly created BASETYPE variables and the expressions are used to subset the input dataset.

Details

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.

Author(s)

Thomas Neitmann

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

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