Learn R Programming

R.AlphA.Home (version 2.0.2)

sepThsd: Quick Number Formatting with Custom Defaults

Description

A wrapper for the `format` function, designed to format numbers with custom defaults for thousands separator, number of significant digits, and scientific notation.

Usage

sepThsd(x, big.mark = " ", digits = 1, scientific = FALSE)

Value

A character vector of formatted numbers.

Arguments

x

Numeric. The input values to format.

big.mark

Character. The separator for thousands (e.g., `" "` for "1 000" or `","` for "1,000"). Default is `" "`.

digits

Integer. The number of significant digits to display. Default is `1`.

scientific

Logical. Should the numbers be displayed in scientific notation? Default is `FALSE`.

Examples

Run this code
# Format with a comma as a thousands separator and 3 significant digits
sepThsd(1234567.89, big.mark = ",", digits = 3)
# Use scientific notation
sepThsd(1234567.89, scientific = TRUE)

Run the code above in your browser using DataLab