Description Usage Arguments Details Value Author(s) Examples
View source: R/derive_var_extreme_flag.R
Adds a Variable Flagging the Maximal / Minimal Value Within a Group of Observations
1 2 3 4 5 6 7 8 9 10 11 12 | derive_var_worst_flag(
dataset,
by_vars,
order,
new_var,
param_var,
analysis_var,
worst_high,
worst_low,
filter = NULL,
check_type = "warning"
)
|
dataset |
Input dataset.
Variables specified by |
by_vars |
Grouping variables Permitted Values: list of variables |
order |
Sort order. Used to determine maximal / minimal observation if they are not unique, see Details section for more information. |
new_var |
Variable to add to the |
param_var |
Variable with the parameter values for which the maximal / minimal value is calculated. |
analysis_var |
Variable with the measurement values for which the maximal / minimal value is calculated. |
worst_high |
Character with |
worst_low |
Character with |
filter |
Filter for flag data Only observations fulfilling the specified condition are taken into account for flagging. If the parameter is not specified, all observations are considered. Permitted Values: a condition |
check_type |
Check uniqueness? If Default: Permitted Values: |
For each group with respect to the variables specified by the by_vars
parameter,
the maximal / minimal observation of analysis_var
is labelled in the new_var
column as "Y"
if its param_var
is in worst_high
/ worst_low
,
otherwise it is assigned NA
.
If there is more than one such maximal / minimal observation,
the first one with respect to the order specified by the order
parameter is flagged.
The input dataset with the new flag variable added.
Ondrej Slama
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 | input <- tibble::tribble(
~STUDYID, ~USUBJID, ~PARAMCD, ~AVISIT, ~ADT, ~AVAL,
"TEST01", "PAT01", "PARAM01", "BASELINE", as.Date("2021-04-27"), 15.0,
"TEST01", "PAT01", "PARAM01", "BASELINE", as.Date("2021-04-25"), 14.0,
"TEST01", "PAT01", "PARAM01", "BASELINE", as.Date("2021-04-23"), 15.0,
"TEST01", "PAT01", "PARAM01", "WEEK 1", as.Date("2021-04-27"), 10.0,
"TEST01", "PAT01", "PARAM01", "WEEK 2", as.Date("2021-04-30"), 12.0,
"TEST01", "PAT02", "PARAM01", "SCREENING",as.Date("2021-04-27"), 15.0,
"TEST01", "PAT02", "PARAM01", "BASELINE", as.Date("2021-04-25"), 14.0,
"TEST01", "PAT02", "PARAM01", "BASELINE", as.Date("2021-04-23"), 15.0,
"TEST01", "PAT02", "PARAM01", "WEEK 1", as.Date("2021-04-27"), 10.0,
"TEST01", "PAT02", "PARAM01", "WEEK 2", as.Date("2021-04-30"), 12.0,
"TEST01", "PAT01", "PARAM02", "SCREENING",as.Date("2021-04-27"), 15.0,
"TEST01", "PAT01", "PARAM02", "SCREENING",as.Date("2021-04-25"), 14.0,
"TEST01", "PAT01", "PARAM02", "SCREENING",as.Date("2021-04-23"), 15.0,
"TEST01", "PAT01", "PARAM02", "BASELINE", as.Date("2021-04-27"), 10.0,
"TEST01", "PAT01", "PARAM02", "WEEK 2", as.Date("2021-04-30"), 12.0,
"TEST01", "PAT02", "PARAM02", "SCREENING",as.Date("2021-04-27"), 15.0,
"TEST01", "PAT02", "PARAM02", "BASELINE", as.Date("2021-04-25"), 14.0,
"TEST01", "PAT02", "PARAM02", "WEEK 1", as.Date("2021-04-23"), 15.0,
"TEST01", "PAT02", "PARAM02", "WEEK 1", as.Date("2021-04-27"), 10.0,
"TEST01", "PAT02", "PARAM02", "BASELINE", as.Date("2021-04-30"), 12.0,
"TEST01", "PAT02", "PARAM03", "SCREENING",as.Date("2021-04-27"), 15.0,
"TEST01", "PAT02", "PARAM03", "BASELINE", as.Date("2021-04-25"), 14.0,
"TEST01", "PAT02", "PARAM03", "WEEK 1", as.Date("2021-04-23"), 15.0,
"TEST01", "PAT02", "PARAM03", "WEEK 1", as.Date("2021-04-27"), 10.0,
"TEST01", "PAT02", "PARAM03", "BASELINE", as.Date("2021-04-30"), 12.0
)
derive_var_worst_flag(
input,
by_vars = vars(USUBJID, PARAMCD, AVISIT),
order = vars(desc(ADT)),
new_var = WORSTFL,
param_var = PARAMCD,
analysis_var = AVAL,
worst_high = c("PARAM01", "PARAM03"),
worst_low = "PARAM02"
)
## Not run:
# example with ADVS
derive_var_worst_flag(
advs,
by_vars = vars(USUBJID, PARAMCD, AVISIT),
order = vars(ADT, ATPTN),
new_var = WORSTFL,
param_var = PARAMCD,
analysis_var = AVAL,
worst_high = c("SYSBP", "DIABP"),
worst_low = "RESP",
filter = !is.na(AVISIT) & !is.na(AVAL)
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.