Sensible rounding for printing.

rnd(x, digits = 3)

Arguments

x

A numeric vector

digits

Digits to round to. Default is 3.

Value

A character vector suitable for printed output.

Details

This is the rounding many are wanting for printing out results. For example, there will always be digits number of decimal places, and trailing zeros will be kept.

Examples

library(tidyext) set.seed(123) rnd(rnorm(10))
#> [1] "-0.560" "-0.230" " 1.559" " 0.071" " 0.129" " 1.715" " 0.461" "-1.265" #> [9] "-0.687" "-0.446"
rnd(1)
#> [1] "1.000"