getNDecimals: Get number of decimals for a specific vector.

View source: R/decimals.R

getNDecimalsR Documentation

Get number of decimals for a specific vector.

Description

The number of decimals is extracted either:

  • from specific implemented rule : see getNDecimalsRule for further details

  • from the data itself: see getNDecimalsData for further details

  • both criterias: in this case the minimum of the number of decimals for both criterias is used

Usage

getNDecimals(x, useRule = TRUE, rule = "1", useData = TRUE)

Arguments

x

Numeric vector.

useRule

Logical (TRUE by default), should the rule be applied?

rule

Character vector with rule to use to derive the number of parameters. Currently only: '1' is implemented.

  • '1': standard rule for the number of decimals for individual values for a continuous variable:

    • value < 1 ('very small values'): 3

    • value < 10: 2

    • value in [10, 1000[: 1

    • value >= 1000: 0

useData

Logical (TRUE by default), should the number of decimals be extracted based on the input data x?

Value

Numeric vector of same length than x with the number of decimals.

Author(s)

Laure Cougnaud

See Also

Other decimals: formatPercentage(), getMaxNDecimalsData(), getMaxNDecimals(), getNDecimalsData()

Examples

x <- c(0.99, 5.679, 50.45, 1450)
# extract number of decimals based on data:
getNDecimals(x, useRule = FALSE, useData = TRUE)
# extract number of decimals based on pre-defined rule:
getNDecimals(x, useRule = TRUE, useData = FALSE)
# extract number of decimals based on both rules
# minimum of both is used (by default)
getNDecimals(x, useRule = TRUE, useData = TRUE)

inTextSummaryTable documentation built on Sept. 12, 2023, 5:06 p.m.