Can run on any data.frame with at least one numeric column. This function defaults to excluding the first column of the input data.frame, assuming that it contains a descriptive variable, but this can be overridden by specifying the columns to round in the ...
argument.
If you're formatting percentages, e.g., the result of adorn_percentages()
, use adorn_pct_formatting()
instead. This is a more flexible variant for ad-hoc usage. Compared to adorn_pct_formatting()
, it does not multiply by 100 or pad the numbers with spaces for alignment in the results data.frame. This function retains the class of numeric input columns.
adorn_rounding(dat, digits = 1, rounding = "half to even", ...)
dat | a |
---|---|
digits | how many digits should be displayed after the decimal point? |
rounding | method to use for rounding - either "half to even", the base R default method, or "half up", where 14.5 rounds up to 15. |
... | columns to adorn. This takes a tidyselect specification. By default, all numeric columns (besides the initial column, if numeric) are adorned, but this allows you to manually specify which columns should be adorned, for use on a data.frame that does not result from a call to |
Returns the data.frame with rounded numeric columns.
mtcars %>% tabyl(am, cyl) %>% adorn_percentages() %>% adorn_rounding(digits = 2, rounding = "half up")#> am 4 6 8 #> 0 0.16 0.21 0.63 #> 1 0.62 0.23 0.15#> #>#>#> #>#>#> #>#> am 4 6 8 dummy #> 0 0.1 0.1 0.4 a #> 1 0.2 0.1 0.1 a# control the columns modified using the ... argument: mtcars %>% tabyl(am, cyl) %>% adorn_percentages("row") %>% adorn_rounding(digits = 1, rounding = "half up", starts_with("8"))#> am 4 6 8 #> 0 0.1578947 0.2105263 0.6 #> 1 0.6153846 0.2307692 0.2