R/summaryfactorlist.R
summary_factorlist_stratified.Rd
A function that takes a single dependent variable with a vector of explanatory variable names (continuous or categorical variables) to produce a summary table.
summary_factorlist_stratified(
.data,
...,
split,
colname_sep = "|",
level_max_length = 10,
n_common_cols = 2
)
Dataframe.
Arguments to summary_factorlist
.
Quoted variable name to stratify columns by.
Separator for creation of new column name.
Maximum name for each factor level contributing to column name.
Number of common columns in summary_factorlist
table, usually 2.
Dataframe.
This function aims to produce publication-ready summary tables for
categorical or continuous dependent variables. It usually takes a categorical
dependent variable to produce a cross table of counts and proportions
expressed as percentages or summarised continuous explanatory variables.
However, it will take a continuous dependent variable to produce mean
(standard deviation) or median (interquartile range) for use with linear
regression models.
Stratify a summary_factorlist
table (beta testing)
# Table 1 - Perforation status stratified by sex ----
explanatory = c("age", "obstruct.factor")
dependent = "perfor.factor"
# Single split
colon_s %>%
summary_factorlist_stratified(dependent, explanatory, split = c("sex.factor"))
#> label levels No|Female Yes|Female No|Male Yes|Male
#> Age (years) Mean (SD) 59.5 (12.3) 60.2 (10.2) 60.1 (11.5) 56.7 (15.8)
#> Obstruction No 334 (78.8) 12 (92.3) 381 (83.4) 5 (35.7)
#> Yes 90 (21.2) 1 (7.7) 76 (16.6) 9 (64.3)
# Double split
colon_s %>%
summary_factorlist_stratified(dependent, explanatory, split = c("sex.factor", "age.factor"))
#> label levels No|Female|<40 years Yes|Female|<40 years
#> Age (years) Mean (SD) 34.3 (4.5)
#> Obstruction No 26 (68.4) 0 (NaN)
#> Yes 12 (31.6) 0 (NaN)
#> No|Female|40-59 year Yes|Female|40-59 year No|Female|60+ years
#> 52.0 (5.5) 51.7 (4.8) 68.7 (5.5)
#> 123 (77.8) 5 (83.3) 185 (81.1)
#> 35 (22.2) 1 (16.7) 43 (18.9)
#> Yes|Female|60+ years No|Male|<40 years Yes|Male|<40 years No|Male|40-59 year
#> 67.4 (7.6) 34.6 (4.6) 28.5 (2.1) 52.1 (5.5)
#> 7 (100.0) 21 (72.4) 2 (100.0) 137 (81.1)
#> 0 (0.0) 8 (27.6) 0 (0.0) 32 (18.9)
#> Yes|Male|40-59 year No|Male|60+ years Yes|Male|60+ years
#> 47.8 (4.1) 68.2 (5.6) 68.2 (5.7)
#> 0 (0.0) 223 (86.1) 3 (37.5)
#> 4 (100.0) 36 (13.9) 5 (62.5)