df <- data.frame(
USUBJID = as.character(c(1, 2, 1, 4, NA, 6, 6, 8, 9)),
ARM = c("A", "A", "A", "A", "A", "B", "B", "B", "B"),
AGE = c(10, 15, 10, 17, 8, 11, 11, 19, 17),
SEX = c("M", "M", "M", "F", "F", "F", "M", "F", "M")
)
# analyze_num_patients
tbl <- basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
analyze_num_patients("USUBJID", .stats = c("unique")) %>%
build_table(df)
tbl
# summarize_num_patients
tbl <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("SEX") %>%
summarize_num_patients("USUBJID", .stats = "unique_count") %>%
build_table(df)
tbl
# Use the statistics function to count number of unique and nonunique patients.
s_num_patients(x = as.character(c(1, 1, 1, 2, 4, NA)), labelstr = "", .N_col = 6L)
s_num_patients(
x = as.character(c(1, 1, 1, 2, 4, NA)),
labelstr = "",
.N_col = 6L,
count_by = c(1, 1, 2, 1, 1, 1)
)
# Count number of unique and non-unique patients.
df <- data.frame(
USUBJID = as.character(c(1, 2, 1, 4, NA)),
EVENT = as.character(c(10, 15, 10, 17, 8))
)
s_num_patients_content(df, .N_col = 5, .var = "USUBJID")
df_by_event <- data.frame(
USUBJID = as.character(c(1, 2, 1, 4, NA)),
EVENT = c(10, 15, 10, 17, 8)
)
s_num_patients_content(df_by_event, .N_col = 5, .var = "USUBJID", count_by = "EVENT")
Run the code above in your browser using DataLab