Learn R Programming

inlmisc (version 0.2.4)

ToScientific: Format for Scientific Notation

Description

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

Usage

ToScientific(x, digits = format.info(as.numeric(x))[2],
  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 https://www.section508.gov, an “x” is used as the label separator for the plotmath type---rather than the more common “%*%” seperator.

Examples

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

Run the code above in your browser using DataLab