Scientific formatter.

scientific_format(digits = 3, scale = 1, prefix = "", suffix = "",
  decimal.mark = ".", trim = TRUE, ...)

scientific(x, digits = 3, scale = 1, prefix = "", suffix = "",
  decimal.mark = ".", trim = TRUE, ...)

Arguments

digits

Number of significant digits to show.

scale

A scaling factor: x will be multiply by scale before formating (useful if the underlying data is on another scale, e.g. for computing percentages or thousands).

prefix, suffix

Symbols to display before and after value.

decimal.mark

The character to be used to indicate the numeric decimal point.

trim

Logical, if FALSE, values are right-justified to a common width (see base::format()).

...

Other arguments passed on to base::format().

x

A numeric vector to format.

Value

A function with single parameter x, a numeric vector, that returns a character vector.

Examples

scientific_format()(1:10)
#> [1] "1e+00" "2e+00" "3e+00" "4e+00" "5e+00" "6e+00" "7e+00" "8e+00" "9e+00" #> [10] "1e+01"
scientific_format()(runif(10))
#> [1] "7.28e-01" "8.73e-01" "3.82e-01" "8.93e-01" "8.44e-01" "7.30e-01" #> [7] "3.84e-02" "3.34e-01" "7.49e-01" "9.13e-01"
scientific_format(digits = 2)(runif(10))
#> [1] "2.0e-01" "4.7e-01" "3.9e-01" "3.9e-01" "2.2e-01" "7.2e-03" "3.6e-01" #> [8] "5.3e-01" "8.4e-01" "1.4e-01"
scientific(1:10)
#> [1] "1e+00" "2e+00" "3e+00" "4e+00" "5e+00" "6e+00" "7e+00" "8e+00" "9e+00" #> [10] "1e+01"
scientific(runif(10))
#> [1] "3.76e-01" "2.63e-01" "4.98e-01" "1.95e-02" "8.72e-02" "9.96e-01" #> [7] "9.42e-01" "1.24e-01" "1.15e-01" "3.67e-01"
scientific(runif(10), digits = 2)
#> [1] "4.7e-01" "7.8e-01" "4.9e-01" "1.0e-01" "9.4e-01" "7.1e-01" "5.0e-01" #> [8] "5.3e-01" "2.6e-01" "7.1e-01"
scientific(12345, suffix = " cells/mL")
#> [1] "1.23e+04 cells/mL"