R/prepapre_descriptive_table.R
prepare_descriptive_table.Rd
Reads a data frame and reports descriptive statistics (n, mean, standard deviation, minimum, first quartile, median, third quartile, maximum) for all members of the data frame that are either numeric or logical.
prepare_descriptive_table( df, digits = c(0, 3, 3, 3, 3, 3, 3, 3), format = "html" )
df | Data frame containing at least one variable that is either numeric or logical and at least two observations. |
---|---|
digits | Number of decimal digits that you want to be displayed for each column. If you provide NA, then the column is omitted from the output. |
format | character scalar that is handed over to |
A list containing two items.
A data frame containing the descriptive table
The return value provided by kable
containing the formatted table
The digits
parameter from prepare_descriptive_table()
uses the default method of
kable
to format numbers, calling round
. This implies that trailing zeroes are
just omitted.
t <- prepare_descriptive_table(mtcars) t$df#> N Mean Std. dev. Min. 25 % Median 75 % Max. #> mpg 32 20.090625 6.0269481 10.400 15.42500 19.200 22.80 33.900 #> cyl 32 6.187500 1.7859216 4.000 4.00000 6.000 8.00 8.000 #> disp 32 230.721875 123.9386938 71.100 120.82500 196.300 326.00 472.000 #> hp 32 146.687500 68.5628685 52.000 96.50000 123.000 180.00 335.000 #> drat 32 3.596563 0.5346787 2.760 3.08000 3.695 3.92 4.930 #> wt 32 3.217250 0.9784574 1.513 2.58125 3.325 3.61 5.424 #> qsec 32 17.848750 1.7869432 14.500 16.89250 17.710 18.90 22.900 #> vs 32 0.437500 0.5040161 0.000 0.00000 0.000 1.00 1.000 #> am 32 0.406250 0.4989909 0.000 0.00000 0.000 1.00 1.000 #> gear 32 3.687500 0.7378041 3.000 3.00000 4.000 4.00 5.000 #> carb 32 2.812500 1.6152000 1.000 2.00000 2.000 4.00 8.000