Description Usage Arguments Details Value Author(s) Examples
View source: R/derive_var_extreme_flag.R
Deprecated, please use derive_var_extreme_flag()
instead.
Add a variable flagging the first or last observation within each by group
1 2 3 4 5 6 7 8 9 | derive_extreme_flag(
dataset,
by_vars,
order,
new_var,
mode,
filter = NULL,
check_type = "warning"
)
|
dataset |
Input dataset The variables specified by the |
by_vars |
Grouping variables Permitted Values: list of variables |
order |
Sort order The first or last observation is determined with respect to the specified order. Permitted Values: list of variables or functions of variables |
new_var |
Variable to add The specified variable is added to the output dataset. It is set to Permitted Values: list of name-value pairs |
mode |
Flag mode Determines of the first or last observation is flagged. Permitted Values: |
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 for the
by_vars
parameter), new_var
is set to "Y" for the first or last observation
(with respect to the order specified for the order
parameter and the flag mode
specified for the mode
parameter). Only observations included by the filter
parameter
are considered for flagging.
Otherwise, new_var
is set to NA
.
The input dataset with the new flag variable added
Stefan Bundfuss
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 | library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data("vs")
# Flag last value for each patient, test, and visit, baseline observations are ignored
vs %>%
derive_extreme_flag(
by_vars = vars(USUBJID, VSTESTCD, VISIT),
order = vars(VSTPTNUM),
new_var = LASTFL,
mode = "last",
filter = VISIT != "BASELINE"
) %>%
arrange(USUBJID, VSTESTCD, VISITNUM, VSTPTNUM) %>%
select(USUBJID, VSTESTCD, VISIT, VSTPTNUM, VSSTRESN, LASTFL)
# Baseline (ABLFL) examples:
input <- tibble::tribble(
~STUDYID, ~USUBJID, ~PARAMCD, ~AVISIT, ~ADT, ~AVAL, ~DTYPE,
"TEST01", "PAT01", "PARAM01", "BASELINE", as.Date("2021-04-27"), 15.0, NA,
"TEST01", "PAT01", "PARAM01", "BASELINE", as.Date("2021-04-25"), 14.0, NA,
"TEST01", "PAT01", "PARAM01", "BASELINE", as.Date("2021-04-23"), 15.0, "AVERAGE",
"TEST01", "PAT01", "PARAM01", "WEEK 1", as.Date("2021-04-27"), 10.0, "AVERAGE",
"TEST01", "PAT01", "PARAM01", "WEEK 2", as.Date("2021-04-30"), 12.0, NA,
"TEST01", "PAT02", "PARAM01", "SCREENING",as.Date("2021-04-27"), 15.0, "AVERAGE",
"TEST01", "PAT02", "PARAM01", "BASELINE", as.Date("2021-04-25"), 14.0, "AVERAGE",
"TEST01", "PAT02", "PARAM01", "BASELINE", as.Date("2021-04-23"), 15.0, "AVERAGE",
"TEST01", "PAT02", "PARAM01", "WEEK 1", as.Date("2021-04-27"), 10.0, "AVERAGE",
"TEST01", "PAT02", "PARAM01", "WEEK 2", as.Date("2021-04-30"), 12.0, "AVERAGE",
"TEST01", "PAT01", "PARAM02", "SCREENING",as.Date("2021-04-27"), 15.0, "AVERAGE",
"TEST01", "PAT01", "PARAM02", "SCREENING",as.Date("2021-04-25"), 14.0, "AVERAGE",
"TEST01", "PAT01", "PARAM02", "SCREENING",as.Date("2021-04-23"), 15.0, NA,
"TEST01", "PAT01", "PARAM02", "BASELINE", as.Date("2021-04-27"), 10.0, "AVERAGE",
"TEST01", "PAT01", "PARAM02", "WEEK 2", as.Date("2021-04-30"), 12.0, NA,
"TEST01", "PAT02", "PARAM02", "SCREENING",as.Date("2021-04-27"), 15.0, NA,
"TEST01", "PAT02", "PARAM02", "BASELINE", as.Date("2021-04-25"), 14.0, NA,
"TEST01", "PAT02", "PARAM02", "WEEK 1", as.Date("2021-04-23"), 15.0, NA,
"TEST01", "PAT02", "PARAM02", "WEEK 1", as.Date("2021-04-27"), 10.0, NA,
"TEST01", "PAT02", "PARAM02", "BASELINE", as.Date("2021-04-30"), 12.0, NA
)
# Last observation
derive_extreme_flag(
input,
by_vars = vars(USUBJID, PARAMCD),
order = vars(ADT),
new_var = ABLFL,
mode = "last",
filter = AVISIT == "BASELINE"
)
# Worst observation - Direction = High
derive_extreme_flag(
input,
by_vars = vars(USUBJID, PARAMCD),
order = vars(AVAL, ADT),
new_var = ABLFL,
mode = "last",
filter = AVISIT == "BASELINE"
)
# Worst observation - Direction = Lo
derive_extreme_flag(
input,
by_vars = vars(USUBJID, PARAMCD),
order = vars(desc(AVAL), ADT),
new_var = ABLFL,
mode = "last",
filter = AVISIT == "BASELINE"
)
# Average observation
derive_extreme_flag(
input,
by_vars = vars(USUBJID, PARAMCD),
order = vars(ADT, desc(AVAL)),
new_var = ABLFL,
mode = "last",
filter = AVISIT == "BASELINE" & DTYPE == "AVERAGE"
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.