library(dplyr)
df <- data.frame(
USUBJID = as.character(c(1:6, 1)),
ARM = factor(c("A", "A", "A", "B", "B", "B", "A"), levels = c("A", "B")),
AETOXGR = factor(c(1, 2, 3, 4, 1, 2, 3), levels = c(1:5)),
AESEV = factor(
x = c("MILD", "MODERATE", "SEVERE", "MILD", "MILD", "MODERATE", "SEVERE"),
levels = c("MILD", "MODERATE", "SEVERE")
),
stringsAsFactors = FALSE
)
df_adsl <- df %>%
select(USUBJID, ARM) %>%
unique()
# Layout creating function with custom format.
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_occurrences_by_grade(
var = "AESEV",
.formats = c("count_fraction" = "xx.xx (xx.xx%)")
) %>%
build_table(df, alt_counts_df = df_adsl)
# Define additional grade groupings.
grade_groups <- list(
"-Any-" = c("1", "2", "3", "4", "5"),
"Grade 1-2" = c("1", "2"),
"Grade 3-5" = c("3", "4", "5")
)
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_occurrences_by_grade(
var = "AETOXGR",
grade_groups = grade_groups,
only_grade_groups = TRUE
) %>%
build_table(df, alt_counts_df = df_adsl)
# Layout creating function with custom format.
basic_table() %>%
add_colcounts() %>%
split_rows_by("ARM", child_labels = "visible", nested = TRUE) %>%
summarize_occurrences_by_grade(
var = "AESEV",
.formats = c("count_fraction" = "xx.xx (xx.xx%)")
) %>%
build_table(df, alt_counts_df = df_adsl)
basic_table() %>%
add_colcounts() %>%
split_rows_by("ARM", child_labels = "visible", nested = TRUE) %>%
summarize_occurrences_by_grade(
var = "AETOXGR",
grade_groups = grade_groups
) %>%
build_table(df, alt_counts_df = df_adsl)
s_count_occurrences_by_grade(
df,
.N_col = 10L,
.var = "AETOXGR",
id = "USUBJID",
grade_groups = list("ANY" = levels(df$AETOXGR))
)
a_count_occurrences_by_grade(
df,
.N_col = 10L,
.N_row = 10L,
.var = "AETOXGR",
id = "USUBJID",
grade_groups = list("ANY" = levels(df$AETOXGR))
)
Run the code above in your browser using DataLab