Add column totals to summary_factorlist() output

ff_column_totals(
  df.in,
  .data,
  dependent,
  na_include_dependent = FALSE,
  percent = TRUE,
  digits = c(1, 0),
  label = NULL,
  prefix = "",
  weights = NULL
)

finalfit_column_totals(
  df.in,
  .data,
  dependent,
  na_include_dependent = FALSE,
  percent = TRUE,
  digits = c(1, 0),
  label = NULL,
  prefix = "",
  weights = NULL
)

Arguments

df.in

summary_factorlist() output.

.data

Data frame used to create summary_factorlist().

dependent

Character. Name of dependent variable.

na_include_dependent

Logical. When TRUE, missing data in the dependent variable is included in totals.

percent

Logical. Include percentage.

digits

Integer length 2. Number of digits for (1) percentage, (2) weighted count.

label

Character. Label for total row.

prefix

Character. Prefix for column totals, e.g "N=".

weights

Character vector of length 1: name of column to use for weights.

Value

Data frame.

Examples

explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'
colon_s %>%
 summary_factorlist(dependent, explanatory) %>%
 ff_column_totals(colon_s, dependent)
#> Note: dependent includes missing data. These are dropped.
#>          label      levels      Alive       Died
#> 1  Total N (%)             511 (55.8) 404 (44.2)
#> 2          Age   <40 years   31 (6.1)   36 (8.9)
#> 3              40-59 years 208 (40.7) 131 (32.4)
#> 4                60+ years 272 (53.2) 237 (58.7)
#> 5          Sex      Female 243 (47.6) 194 (48.0)
#> 6                     Male 268 (52.4) 210 (52.0)
#> 7  Obstruction          No 408 (82.1) 312 (78.6)
#> 8                      Yes  89 (17.9)  85 (21.4)
#> 9  Perforation          No 497 (97.3) 391 (96.8)
#> 10                     Yes   14 (2.7)   13 (3.2)

# Ensure works with missing data in dependent
colon_s = colon_s %>%
 dplyr::mutate(
  mort_5yr = forcats::fct_na_value_to_level(mort_5yr, level = "(Missing)")
 )
 colon_s %>%
 summary_factorlist(dependent, explanatory) %>%
 ff_column_totals(colon_s, dependent)
#>          label      levels      Alive       Died  (Missing)
#> 1  Total N (%)             511 (55.0) 404 (43.5)   14 (1.5)
#> 2          Age   <40 years   31 (6.1)   36 (8.9)   3 (21.4)
#> 3              40-59 years 208 (40.7) 131 (32.4)   5 (35.7)
#> 4                60+ years 272 (53.2) 237 (58.7)   6 (42.9)
#> 5          Sex      Female 243 (47.6) 194 (48.0)   8 (57.1)
#> 6                     Male 268 (52.4) 210 (52.0)   6 (42.9)
#> 7  Obstruction          No 408 (82.1) 312 (78.6)  12 (85.7)
#> 8                      Yes  89 (17.9)  85 (21.4)   2 (14.3)
#> 9  Perforation          No 497 (97.3) 391 (96.8) 14 (100.0)
#> 10                     Yes   14 (2.7)   13 (3.2)    0 (0.0)