Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

format_nr

Format a number with a specified number of decimal places, thousand sep, and a symbol


Description

Format a number with a specified number of decimal places, thousand sep, and a symbol

Usage

format_nr(x, sym = "", dec = 2, perc = FALSE, mark = ",", na.rm = TRUE, ...)

Arguments

x

Number or vector

sym

Symbol to use

dec

Number of decimals to show

perc

Display number as a percentage

mark

Thousand separator

na.rm

Remove missing values

...

Additional arguments passed to formatC

Value

Character (vector) in the desired format

Examples

format_nr(2000, "$")
format_nr(2000, dec = 4)
format_nr(.05, perc = TRUE)
format_nr(c(.1, .99), perc = TRUE)
format_nr(data.frame(a = c(.1, .99)), perc = TRUE)
format_nr(data.frame(a = 1:10), sym = "$", dec = 0)
format_nr(c(1, 1.9, 1.008, 1.00))
format_nr(c(1, 1.9, 1.008, 1.00), drop0trailing = TRUE)
format_nr(NA)
format_nr(NULL)

radiant.data

Data Menu for Radiant: Business Analytics using R and Shiny

v1.3.12
AGPL-3 | file LICENSE
Authors
Vincent Nijs [aut, cre]
Initial release
2020-11-25

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.