Learn R Programming

inlmisc (version 0.3.5)

ToScientific: Format for Scientific Notation

Description

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

Usage

ToScientific(x, digits = NULL, type = c("latex", "plotmath"),
  na = as.character(NA), delimiter = "$", scipen = NULL, ...)

Arguments

x

'numeric'. Vector of numbers

digits

'integer'. Number of digits after the decimal point for the coefficent part of a number in scientific notation.

type

'character'. Specify "latex" to return numbers in the LaTeX markup language (default), or "plotmath" to return as plotmath expressions.

na

'character'. String to be used for missing values (NA). By default, no string substitution is made for missing values.

delimiter

'character'. Delimiter for LaTeX mathematical mode, inline ($...$) by default.

scipen

'integer'. A penalty to be applied when deciding to format numeric values in scientific or fixed notation. Positive values bias towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than scipen digits wider. By default, all numbers, with the exception of zero, are formatted in scientific notation.

...

Arguments passed to the formatC function. Only applies to fixed formatted values that are not equal to zero.

Value

For type = "latex", returns a 'character' vector of the same length as argument x. And for type = "plotmath", returns an 'expression' vector of the same length as x.

Examples

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

x <- exp(log(10) * 1:6)
i <- seq_along(x)
plot(i, i, type = "n", xaxt = "n", yaxt = "n", ann = FALSE)
lab <- ToScientific(x, 0L, type = "plotmath", scipen = 0L, big.mark = ",")
axis(1, i, labels = lab)
axis(2, i, labels = lab)

# }

Run the code above in your browser using DataLab