format_number: format number

View source: R/formatters.R

format_numberR Documentation

format number

Description

Number formatters to apply to a column in a dataframe. Helpful for displaying tibbles in console or in conjunction with make_flextable. Based off the formattable package.

Usage

format_number(tbl, ..., digits = 0)

format_percent(tbl, ..., digits = 0)

format_currency(tbl, ..., symbol = "yen", digits = 0)

Arguments

tbl

dataframe

...

tidyselect.

digits

integer. trailing digits

symbol

chr. currency symbol

Details

  • format_number formats a number accounting style by inserting commas. default selection is integer columns

  • format_percent formats a number as a percentage. default selection is numeric columns in between -1 and 1.

  • format_currency formats a monetary value with the currency symbol. default currency symbol is yen.

Value

dataframe

dataframe

Examples


tibble::tibble(
y = seq(1000L, 10000L, by = 1000L),
z = c(-.59, -.23, -.11, 0, .1, .21, .3, .4, .6, .9),
w = c(.1, 1.4, .23, -.10, 0, -2.3, .2,.3,.4,.5)) -> tbl1

tbl1

# automatically formats the integer column
tbl1 %>%
format_number()

# automatically formats to yen
tbl1 %>%
format_currency(y)

# automatically detects columns between -1 and 1 to convert to percentages
tbl1 %>%
format_percent()

# select specific columns to convert.
tbl1 %>%
format_percent(z, w)


presenter documentation built on Feb. 16, 2023, 5:13 p.m.