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)
)
Run the code above in your browser using DataLab