library(dplyr)
df <- data.frame(
USUBJID = as.character(c(1, 1, 2, 2)),
ANRIND = factor(c("NORMAL", "LOW", "HIGH", "HIGH")),
BNRIND = factor(c("NORMAL", "NORMAL", "HIGH", "HIGH")),
ONTRTFL = c("", "Y", "", "Y"),
stringsAsFactors = FALSE
)
# Select only post-baseline records.
df <- df %>%
filter(ONTRTFL == "Y")
# Layout creating function.
basic_table() %>%
count_abnormal(var = "ANRIND", abnormal = list(high = "HIGH", low = "LOW")) %>%
build_table(df)
# Passing of statistics function and formatting arguments.
df2 <- data.frame(
ID = as.character(c(1, 1, 2, 2)),
RANGE = factor(c("NORMAL", "LOW", "HIGH", "HIGH")),
BL_RANGE = factor(c("NORMAL", "NORMAL", "HIGH", "HIGH")),
ONTRTFL = c("", "Y", "", "Y"),
stringsAsFactors = FALSE
)
# Select only post-baseline records.
df2 <- df2 %>%
filter(ONTRTFL == "Y")
basic_table() %>%
count_abnormal(
var = "RANGE",
abnormal = list(low = "LOW", high = "HIGH"),
variables = list(id = "ID", baseline = "BL_RANGE")
) %>%
build_table(df2)
Run the code above in your browser using DataLab