View source: R/derive_var_shift.R
derive_var_shift | R Documentation |
Derives a character shift variable containing concatenated shift in values based on user-defined pairing, e.g., shift from baseline to analysis value, shift from baseline grade to analysis grade, ...
derive_var_shift(
dataset,
new_var,
from_var,
to_var,
missing_value = "NULL",
sep_val = " to "
)
dataset |
Input dataset The variables specified by the |
new_var |
Name of the character shift variable to create. |
from_var |
Variable containing value to shift from. |
to_var |
Variable containing value to shift to. |
missing_value |
Character string to replace missing values in Default: "NULL" |
sep_val |
Character string to concatenate values of Default: " to " |
new_var
is derived by concatenating the values of from_var
to values of to_var
(e.g. "NORMAL to HIGH"). When from_var
or to_var
has missing value, the
missing value is replaced by missing_value
(e.g. "NORMAL to NULL").
The input dataset with the character shift variable added
BDS-Findings Functions that returns variable appended to dataset:
derive_basetype_records()
,
derive_var_analysis_ratio()
,
derive_var_anrind()
,
derive_var_atoxgr()
,
derive_var_atoxgr_dir()
,
derive_var_base()
,
derive_var_chg()
,
derive_var_ontrtfl()
,
derive_var_pchg()
library(tibble)
data <- tribble(
~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BNRIND, ~ANRIND,
"P01", "ALB", 33, "Y", "LOW", "LOW",
"P01", "ALB", 38, NA, "LOW", "NORMAL",
"P01", "ALB", NA, NA, "LOW", NA,
"P02", "ALB", 37, "Y", "NORMAL", "NORMAL",
"P02", "ALB", 49, NA, "NORMAL", "HIGH",
"P02", "SODIUM", 147, "Y", "HIGH", "HIGH"
)
data %>%
convert_blanks_to_na() %>%
derive_var_shift(
new_var = SHIFT1,
from_var = BNRIND,
to_var = ANRIND
)
# or only populate post-baseline records
data %>%
convert_blanks_to_na() %>%
restrict_derivation(
derivation = derive_var_shift,
args = params(
new_var = SHIFT1,
from_var = BNRIND,
to_var = ANRIND
),
filter = is.na(ABLFL)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.