Learn R Programming

lares (version 4.10.6)

formatNum: Nicely Format Numerical Values

Description

This function lets the user format numerical values nicely

Usage

formatNum(
  x,
  decimals = 2,
  signif = NULL,
  type = Sys.getenv("LARES_NUMFORMAT"),
  pre = "",
  pos = "",
  sign = FALSE,
  abbr = FALSE,
  ...
)

Arguments

x

Numerical Vector

decimals

Integer. Amount of decimals to display.

signif

Integer. Rounds the values in its first argument to the specified number of significant digits.

type

Integer. 1 for International standards. 2 for American Standards. Use Sys.setenv("LARES_NUMFORMAT" = 2) to set this parameter globally.

pre, pos

Character. Add string before or after number.

sign

Boolean. Add + sign to positive values.

abbr

Boolean. Abbreviate using num_abbr()? You can use the `decimals` parameter to set abbr's n(-1) parameter.

...

Additional lazy eval parameters.

Value

Character. String vector with reformatted continuous numbers

See Also

Other Data Wrangling: balance_data(), categ_reducer(), cleanText(), date_cuts(), date_feats(), holidays(), impute(), left(), normalize(), numericalonly(), ohe_commas(), ohse(), removenacols(), removenarows(), replaceall(), textFeats(), textTokenizer(), vector2text(), year_month(), year_week()

Examples

Run this code
# NOT RUN {
formatNum(1.23456, decimals = 3)
formatNum(1.23456, type = 1)
formatNum(1.23456, pre = "$", pos = "/person")
formatNum(123456, abbr = TRUE)
formatNum(1234567890, abbr = TRUE, signif = 2)
formatNum(1234567890, decimals = 0, abbr = TRUE)
formatNum(c(-3:3), sign = TRUE)
# }

Run the code above in your browser using DataLab