#' When a grouping variable count_by has more than two levels, this utility collapses all of the level-specific columns
Usage
collapse_counts(df, count_by)
Arguments
- df
A data.frame produced by one of the TableSubgroup functions
- count_by
A string giving the name of the variable whose per-level
count columns should be collapsed. If NULL, df is returned unmodified.
Value
A data.frame identical to `f except that:
All Count(count_by=…) columns are removed.
A single column Count(by count_by) remains, containing the first
non-missing, non-empty value from the original per-level columns.
Details
This helper is intended for internal use by
TableSubgroupCox(), TableSubgroupMultiCox(), and their GLM equivalents.
It simplifies reporting when you request counts stratified by a factor with
more than two levels.