clinical_summary <- function(data, ..., na.rm = TRUE, digits = 2) {
data %>%
summarise(
across(c(...), list(
mean = ~ round(mean(.x, na.rm = na.rm), digits),
sd = ~ round(sd(.x, na.rm = na.rm), digits),
min = ~ min(.x, na.rm = na.rm),
max = ~ max(.x, na.rm = na.rm)
))
)
}
# Create demo data for testing
demo <- tibble(
USUBJID = paste0("001-", sprintf("%03d", 1:10)),
AGE = c(23, 45, 67, 52, 71, 34, 58, 63, 29, 76),
SEX = c("F", "M", "F", "M", "F", "F", "M", "F", "M", "F"),
WEIGHT = c(65, 80, 58, 75, 62, 70, 85, 60, 78, 55),
HEIGHT = c(160, 175, 155, 180, 158, 165, 185, 162, 172, 150),
RFSTDTC = "2024-01-15"
)
# Test summary function
cat("Clinical summary for AGE and WEIGHT:\n")