Reorders the sections of a tbl_hierarchical() or
tbl_hierarchical_count() table. "descending" (the default) orders the
rows of each hierarchy variable by the sum of their counts across the
table's columns, highest first, with ties keeping their order;
"alphanumeric" restores the byte order of the level text. The overall
row stays first, and each summary row stays above its section.
Arguments
- x
(
tbl_hierarchical,tbl_hierarchical_count)
A hierarchical table.- sort
(formula-list)
"descending"(the default) or"alphanumeric", keyed by the hierarchy variables; a single string applies to all of them.- by_level
(
scalar)
One level of the table'sbyvariable, e.g.by_level = "Placebo":"descending"then ranks the rows by the counts in that level's column alone. Default isNULL, the sum over thebylevels. It has no effect on"alphanumeric", and errors when the table has nobyvariable.- ...
Not used.
Details
Sorting a variable outside include descending has no stored counts to
sum, so its sections are ordered by the summed rates of the first included
variable below it, with a message: subjects counted once in each child
rate can overlap, so the sum may exceed the section's true rate.
See also
Other hierarchical tables:
add_difference_hierarchical,
filter_hierarchical(),
tbl_hierarchical()
Examples
ae <- data.frame(
id = c(1L, 1L, 1L, 2L, 2L, 3L, 5L, 5L, 6L),
trt = c("A", "A", "A", "A", "A", "A", "B", "B", "B"),
soc = c("Nervous", "Nervous", "Gastro", "Nervous", "Gastro",
"Gastro", "Nervous", "Gastro", "Gastro"),
term = c("Headache", "Headache", "Nausea", "Dizziness", "Nausea",
"Vomiting", "Headache", "Nausea", "Nausea")
)
enrolled <- data.frame(id = 1:8, trt = rep(c("A", "B"), each = 4))
# Example 1 ----------------------------------
tbl_hierarchical(ae, variables = c(soc, term), by = trt,
denominator = enrolled, id = id) |>
sort_hierarchical()
# Example 2 ----------------------------------
# order by the counts of one arm
tbl_hierarchical(ae, variables = c(soc, term), by = trt,
denominator = enrolled, id = id) |>
sort_hierarchical(by_level = "B")