A family of functions for formatting numbers and then padding with spaces so that table columns can be both centered and decimal aligned.

pad_counts(x, digits = 0L)

pad_prop(x, digits, fmt_small = TRUE, keep_zero = FALSE, output = NULL)

pad_corr(x, digits, output = NULL)

pad_decimal(x, digits, output = NULL)

Arguments

x

Number or number string to be formatted

digits

Number of decimal places to retain

fmt_small

Indicator for replacing zero with < (e.g., .000 becomes < .001). Default is TRUE.

keep_zero

If fmt_small is TRUE, whether to preserve true 0s (e.g., 0.0000001 becomes <.001, but 0.0000000 stays .000).

output

The output type for the rendered document. One of "latex" or "html".

Value

A character vector of the same length as x.

Details

pad_counts should be used to pad integer numbers. This wraps base::format() to add a comma separator.

pad_prop should be used to pad decimal numbers between [0,1]. This wraps fmt_prop() to round to a specified number of digits and optionally remove the leading zero.

pad_corr should be used to pad decimal numbers between [-1,1]. This wraps fmt_corr(), and is similar to pad_prop, but accounts for negative numbers when adding padding.

pad_decimal should be used to pad decimal number that are not bounded. This wraps fmt_digits() to round to a specified number of decimal places.

See also

Other formatters: fmt_table(), formatting

Examples

pad_counts(sample(1:1000, size = 20))
#>  [1] "885"      "435"      "270"      "794"      "\\ \\ 30" "\\ \\ 59"
#>  [7] "683"      "368"      "594"      "229"      "682"      "454"     
#> [13] "920"      "241"      "767"      "725"      "485"      "414"     
#> [19] "766"      "129"     

pad_prop(c(0.001, runif(5)), digits = 2)
#> [1] "<.01\\ \\ \\ " ".95"           ".94"           ".33"          
#> [5] ".33"           ".38"          

pad_corr(runif(10, -1, 1), digits = 2)
#>  [1] ".02"              ".29"              "&minus;.57\\ \\ " ".49"             
#>  [5] ".53"              "&minus;.95\\ \\ " "&minus;.07\\ \\ " ".62"             
#>  [9] ".15"              ".89"             

pad_decimal(runif(10, 1, 100), digits = 1)
#>  [1] "18.9"      "23.8"      "91.6"      "12.9"      "29.2"      "63.6"     
#>  [7] "84.2"      "\\ \\ 2.8" "82.5"      "54.1"