makeup_num: Format a numeric vector with custom prefixes and suffixes

View source: R/numbers.R

makeup_numR Documentation

Format a numeric vector with custom prefixes and suffixes

Description

This function formats a numeric vector with custom prefixes and suffixes, and optionally with SI prefixes such as "k" for kilo and "M" for mega. The function uses the scales and d3.format packages to format the values with custom separators, number of decimal places, and locale settings.

Usage

makeup_num(
  v,
  sample = NULL,
  locale = NULL,
  prefix = "",
  suffix = "",
  si_prefix = FALSE,
  scale = 1
)

Arguments

v

A numeric vector to format.

sample

A sample vector with the same data type and range as v to use as a reference for the formatting settings. If not specified, default formatting settings will be used.

locale

A character string specifying the locale settings to use. If not specified, the default locale will be used.

prefix

A character string to prepend to each formatted value.

suffix

A character string to append to each formatted value.

si_prefix

A logical value indicating whether to use SI prefixes such as "k" and "M" to format the values. If TRUE, the values will be formatted with SI prefixes. If FALSE, standard formatting will be used.

scale

A numeric value indicating the scale factor to apply when using SI prefixes. For example, a value of 1000 would use "k" for values above 1000, "M" for values above 1,000,000, etc.

Value

A character vector of formatted values.

Examples

makeup_num(1000000, sample = "1234", si_prefix = TRUE)

datasketch/makeup documentation built on Feb. 21, 2025, 6:53 a.m.