fmt_table1.Rd
The fmt_table1
function calculates descriptive statistics by groups for
continuous, categorical, and dichotomous variables. Review the fmt_table1
vignette for detailed examples.
fmt_table1(data, by = NULL, label = NULL, type = NULL, statistic = NULL, digits = NULL, id = NULL, missing = c("ifany", "always", "no"))
data | data frame. |
---|---|
by | a character name of a categorical variable in data, |
label | A list of variable labels,
e.g. |
type | A list that includes specified summary types. Accepted values
are |
statistic | A list of the type of statistics to return. The list can contain
two names lists ( |
digits | integer indicating the number of decimal places to round continuous
summary statistics. |
id | Character vector of an ID or grouping variable. Summary statistics
will not be printed for this column. The column may be used in |
missing | whether to include |
Data frame including formatted descriptive statistics.
fmt_table1(trial, by = "trt")#> #> Variable Drug Placebo #> N = 107 N = 93 #> Age, yrs 47 (39, 58) 46 (36, 54) #> Unknown 3 5 #> Marker Level, ng/mL 0.61 (0.22, 1.20) 0.72 (0.22, 1.63) #> Unknown 4 4 #> T Stage #> T1 25 (23%) 26 (28%) #> T2 26 (24%) 23 (25%) #> T3 29 (27%) 13 (14%) #> T4 27 (25%) 31 (33%) #> Grade #> I 38 (36%) 29 (31%) #> II 34 (32%) 24 (26%) #> III 35 (33%) 40 (43%) #> Tumor Response 52 (51%) 30 (33%) #> Unknown 6 3# convert numeric 'am' to factor to display nicely in header mtcars %>% dplyr::mutate(am = factor(am, c(0, 1), c("Automatic", "Manual"))) %>% fmt_table1(by = "am") %>% add_comparison()#> #> Variable Automatic Manual p-value #> N = 19 N = 13 #> mpg 17.3 (14.9, 19.2) 22.8 (21.0, 30.4) 0.002 #> cyl 0.009 #> 4 3 (16%) 8 (62%) #> 6 4 (21%) 3 (23%) #> 8 12 (63%) 2 (15%) #> disp 276 (196, 360) 120 (79, 160) <0.001 #> hp 175 (116, 192) 109 (66, 113) 0.044 #> drat 3.15 (3.07, 3.70) 4.08 (3.85, 4.22) <0.001 #> wt 3.52 (3.44, 3.84) 2.32 (1.94, 2.78) <0.001 #> qsec 17.82 (17.18, 19.17) 17.02 (16.46, 18.61) 0.3 #> vs 7 (37%) 7 (54%) 0.6 #> gear <0.001 #> 3 15 (79%) 0 (0%) #> 4 4 (21%) 8 (62%) #> 5 0 (0%) 5 (38%) #> carb 0.3 #> 1 3 (16%) 4 (31%) #> 2 6 (32%) 4 (31%) #> 3 3 (16%) 0 (0%) #> 4 7 (37%) 3 (23%) #> 6 0 (0%) 1 (7.7%) #> 8 0 (0%) 1 (7.7%)