library(dplyr)
## Fabricate dataset
dta_test <- data.frame(
USUBJID = rep(1:6, each = 3),
AVISIT = rep(paste0("V", 1:3), 6),
ARM = rep(LETTERS[1:3], rep(6, 3)),
AVAL = c(9:1, rep(NA, 9))
) %>%
mutate(ABLFLL = AVISIT == "V1") %>%
group_by(USUBJID) %>%
mutate(
BLVAL = AVAL[ABLFLL],
CHG = AVAL - BLVAL
) %>%
ungroup()
results <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("AVISIT") %>%
summarize_change("CHG", variables = list(value = "AVAL", baseline_flag = "ABLFLL")) %>%
build_table(dta_test)
results
Run the code above in your browser using DataLab