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

format_num

Formatting numeric values


Description

Function to format an R object for pretty printing with a specified (k) number of decimal places. The function also allows really small p-values to be denoted as "p < 0.001" rather than "p = 0.000". Note that if p.value is set to TRUE, the minimum value of k allowed is 3. If k is set to less than 3, the function will ignore entered k value and use k = 3 instead.

Usage

format_num(x, k = 3L, p.value = FALSE, ...)

Arguments

x

A numeric value.

k

Number of digits after decimal point (should be an integer) (Default: k = 3L).

p.value

Decides whether the number is a p-value (Default: FALSE).

...

Currently ignored.

Value

Formatted numeric value.

Note

This function is not vectorized.

Examples

format_num(0.0000123, k = 2, p.value = TRUE)
format_num(0.008675, k = 2, p.value = TRUE)
format_num(0.003458, k = 3, p.value = FALSE)

ipmisc

Miscellaneous Functions for Data Cleaning and Analysis

v6.0.2
GPL-3 | file LICENSE
Authors
Indrajeet Patil [aut, cre, cph] (<https://orcid.org/0000-0003-1995-6531>)
Initial release

We don't support your browser anymore

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