Learn R Programming

inlmisc (version 0.5.5)

ToScientific: Format for Scientific Notation

Description

Format numbers in scientific notation \(m \times 10^{n}\).

Usage

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

Arguments

x

'numeric' vector. Numbers

digits

'integer' count. Desired number of digits after the decimal point.

type

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

na

'character' string. Value to use for missing values (NA). By default, no string substitution is made for missing values.

zero

'character' string. Value to use for zero values. Specify as NULL to prevent string substitution.

delimiter

'character' string. Delimiter for LaTeX mathematical mode, inline ($...$) by default. Does not apply to missing value strings.

scipen

'integer' count. 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. Specify NULL to format all numbers, with the exception of zero, in scientific notation.

big.mark

'character' string. Mark inserted between every big interval before the decimal point. By default, commas are placed every 3 decimal places for numbers larger than 999.

...

Not used

Value

When type = "latex" returns a 'character' vector of the same length as argument x. And when type = "plotmath" returns a '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 = 2, na = "---")

ToScientific(x, digits = 2, scipen = 0)

x <- seq(0, 20000, by = 4000)
ToScientific(x, scipen = 0)

lab <- ToScientific(x, type = "plotmath", scipen = 0)
i <- seq_along(x)
plot(i, type = "n", xaxt = "n", yaxt = "n", ann = FALSE)
axis(1, i, labels = lab)
axis(2, i, labels = lab)

# }

Run the code above in your browser using DataLab