Skip to contents

When reporting ratios, such as a relative risk or an odds ratio, the rounding should be similar on each side of the number 1: an odds ratio of 0.95 with a confidence interval of 0.70 to 1.24 is best shown with two decimal places throughout. style_ratio() uses digits significant figures for numbers below 1 and digits + 1 for numbers of 1 and larger, so that 0.123 becomes "0.12", 1.005 becomes "1.01" and 12.3 becomes "12.3".

Usage

style_ratio(
  x,
  digits = 2,
  big.mark = ifelse(decimal.mark == ",", " ", ","),
  decimal.mark = getOption("OutDec"),
  prefix = "",
  suffix = "",
  na = NA_character_,
  ...
)

Arguments

x

(numeric)
Numeric vector.

digits

(integer)
Number of significant figures for values below one.

big.mark

(string)
Character used between every three digits to the left of the decimal mark.

decimal.mark

(string)
Character used as the decimal mark.

prefix, suffix

(string)
Text added before and after each formatted value.

na

(string)
Replacement for missing values.

...

Not used. Accepted so that formatting functions can be called interchangeably.

Value

A character vector the same length as x.

Examples

c(0.123, 0.9, 1.1234, 12.345, 101.234, -0.123, -0.9, -1.1234, -12.345, -101.234) |>
  style_ratio()
#>  [1] "0.12"  "0.90"  "1.12"  "12.3"  "101"   "-0.12" "-0.90" "-1.12" "-12.3"
#> [10] "-101"