pretty_tbl_df.Rd
Take a dataframe and make a new summary dataframe to pass to Kable for pretty table rendering. The input is assumed to have variables in columns with observations in rows.Numeric variables are by default summarised by median and IQR. Character vectors are assumed to be factors and a summarised as a proportion for each level.
pretty_tbl_df( df, vars_to_char = NULL, r = 0, vars_to_specify_rounding = NULL, confint = TRUE )
df | dataframe to make into pretty table |
---|---|
vars_to_char | character vector of names of numeric variables that you want to treat as factors |
r | numeric, number of digits to round to |
vars_to_specify_rounding | named numeric vector c("varname" = m) to hange default rounding for variable varname |
confint | boolean, do you want to report confidence intervals? |
A dataframe with three columns: variable: the original column name levels: the levels of a character variable (one row for each) level OR the text "Median (IQR)" for numeric variables value: the proportion of observations for that level OR median (IQR) for numeric variables
pretty_tbl_df(mtcars)#> variable levels value #> 1 mpg Median (IQR) 19 (15-23) #> 2 cyl Median (IQR) 6 (4-8) #> 3 disp Median (IQR) 196 (121-326) #> 4 hp Median (IQR) 123 (96-180) #> 5 drat Median (IQR) 4 (3-4) #> 6 wt Median (IQR) 3 (3-4) #> 7 qsec Median (IQR) 18 (17-19) #> 8 vs Median (IQR) 0 (0-1) #> 9 am Median (IQR) 0 (0-1) #> 10 gear Median (IQR) 4 (3-4) #> 11 carb Median (IQR) 2 (2-4)