library(tibble)
# Add a variable for the mean of AVAL within each visit
adbds <- tribble(
~USUBJID, ~AVISIT, ~ASEQ, ~AVAL,
"1", "WEEK 1", 1, 10,
"1", "WEEK 1", 2, NA,
"1", "WEEK 2", 3, NA,
"1", "WEEK 3", 4, 42,
"1", "WEEK 4", 5, 12,
"1", "WEEK 4", 6, 12,
"1", "WEEK 4", 7, 15,
"2", "WEEK 1", 1, 21,
"2", "WEEK 4", 2, 22
)
derive_var_merged_summary(
adbds,
dataset_add = adbds,
by_vars = exprs(USUBJID, AVISIT),
new_vars = exprs(
MEANVIS = mean(AVAL, na.rm = TRUE),
MAXVIS = max(AVAL, na.rm = TRUE)
)
)
# Add a variable listing the lesion ids at baseline
adsl <- tribble(
~USUBJID,
"1",
"2",
"3"
)
adtr <- tribble(
~USUBJID, ~AVISIT, ~LESIONID,
"1", "BASELINE", "INV-T1",
"1", "BASELINE", "INV-T2",
"1", "BASELINE", "INV-T3",
"1", "BASELINE", "INV-T4",
"1", "WEEK 1", "INV-T1",
"1", "WEEK 1", "INV-T2",
"1", "WEEK 1", "INV-T4",
"2", "BASELINE", "INV-T1",
"2", "BASELINE", "INV-T2",
"2", "BASELINE", "INV-T3",
"2", "WEEK 1", "INV-T1",
"2", "WEEK 1", "INV-N1"
)
derive_var_merged_summary(
adsl,
dataset_add = adtr,
by_vars = exprs(USUBJID),
filter_add = AVISIT == "BASELINE",
new_vars = exprs(LESIONSBL = paste(LESIONID, collapse = ", "))
)
Run the code above in your browser using DataLab