Round Data
sbf_round_data.RdRounds the numeric columns of a data frame in the same way as the .md
file saved by sbf_save_table() and sbf_save_plot().
Arguments
- x
A data frame.
- proportion
A flag specifying whether the columns
estimate,lower,upperandsdare proportions, in which case significant digits are counted from the nearer of 0 and 1 in the.mdfile.- format_column
A list of two-sided formulas of the form
column ~ fun(.)specifying how to round and format numeric columns other thanestimate,lower,upperandsdin the.mdfile. The function can return a numeric vector, which is formatted without further rounding, or a character vector, which is used as is. The values in the.rdsand.csvfiles are not altered.- round_as_estimate
A character vector of numeric columns, other than
estimate,lower,upper,sdandsvalue, to round in the.mdfile to the same number of decimal places asestimatein the same row (e.g. anobservedvalue compared with the estimate). Rows with a missing estimate are formatted as data. Ifproportion = TRUEthe columns must also be proportions.
Details
The rounding is described in sbf_save_table().
The numeric columns stay numeric, so significant trailing zeros are not
kept when the values are printed; use sbf_as_md() with round = TRUE
to keep them.
Integer columns and columns that are not numeric are not altered.
Columns formatted by format_column are replaced by the values returned by
the function, which are not rounded further.
Examples
x <- data.frame(
estimate = c(0.53124, 12.3456),
lower = c(0.21234, 9.8765),
upper = c(0.87012, 15.4321),
length = c(1.23456, 123.456)
)
sbf_round_data(x)
#> estimate lower upper length
#> 1 0.53 0.21 0.87 1.235
#> 2 12.30 9.90 15.00 123.500
sbf_round_data(x, format_column = list(length ~ round(., 1)))
#> estimate lower upper length
#> 1 0.53 0.21 0.87 1.2
#> 2 12.30 9.90 15.00 123.5