Learn R Programming

descutils (version 1.0)

formatC_mod: Modified formatC with Improved Zero and Exponential Handling

Description

Formats a numeric vector similar to formatC, but tweaks output for certain special cases: - Attempts to remove trailing decimal points for whole numbers. - If format is 'fg' and output is "0", falls back to fixed format (f). - Converts exponential notation to plain numbers where appropriate.

Usage

formatC_mod(x, digits = NULL, format = NULL, ...)

Value

A character vector with formatted numbers.

Arguments

x

A numeric vector.

digits

Integer; desired number of digits.

format

Character string specifying the output format; see formatC. Common are "fg" (significant digits), or "f" (fixed).

...

Further arguments passed to formatC.

Examples

Run this code
formatC_mod(c(3.14159, 42, 0), digits = 2, format = "fg")
formatC_mod(c(1e-6, 42), digits = 2, format = "fg")

Run the code above in your browser using DataLab