Learn R Programming

inlmisc (version 0.3.2)

ToScientific: Format for Scientific Notation

Description

This function formats numbers in scientific notation \(m \times 10^{n}\).

Usage

ToScientific(x, digits = NULL, lab.type = c("latex", "plotmath"))

Arguments

x

'numeric'. Vector of numbers

digits

'integer'. Number of digits after the decimal point for the mantissa.

lab.type

'character'. By default, LaTeX formatted strings for labels are returned. Alternatively, lab.type = "plotmath" returns plotmath-compatible expressions.

Value

For the default lab.type = "latex", a 'character' vector of the same length as argument x. And for lab.type = "plotmath", an expression of the same length as x, typically with elements of the form m x 10^n. In order to comply with Section 508, an "x" is used as the label separator for the plotmath type---rather than the more common "%*%" seperator.

Examples

Run this code
# NOT RUN {
x <- c(-1e+09, 0, NA, pi * 10^(-5:5))
ToScientific(x, digits = 2)
ToScientific(x, digits = 2, lab.type = "plotmath")

x <- seq(0, 2e+06, length.out = 5)
ToScientific(x)

# }

Run the code above in your browser using DataLab