format_numbers: Format values of numeric columns in a dataframe.

Description Usage Arguments Examples

View source: R/format_numbers.R

Description

Function formats numeric columns only. Other classes are left intact.

Usage

1
format_numbers(data, digits = 3, format = "f", fun = formatC, ...)

Arguments

data

A data frame.

digits

(numeric or NA) a desired number of digits after the decimal point (if format = "f") or a number of significant digits (format = "g", = "e" or = "fg").
Either one integer (to set the same formatting for all columns) or a vector of inegers (to set formatting for each column separately).
Use NA to leave column unformatted.

format

(character) "f", "g", "e", "fg". Either one value or a vector of values for each column. Each value will be passed to fun separately.
"f" gives numbers in the usual xxx.xxx format;
"e" and "E" give n.ddde+nn or n.dddE+nn (scientific format);
"g" and "G" put number into scientific format only if it saves space to do so.
"fg" uses fixed format as "f", but digits as the minimum number of significant digits. This can lead to quite long result strings

fun

A function that does the formatting. Default is base::formatC().

...

Other parameters to be passed to fun.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(biostat)
DATA <- head(iris)

# The same rounding for each column
format_numbers(DATA, 2)

# Different rounding for different columns
format_numbers(DATA, c(2, 2, 3, 3, NA))

# Use `NA` to leave a column unformatted
format_numbers(DATA, c(4, NA, 3, NA, NA))

GegznaV/BioStat documentation built on Aug. 14, 2020, 9:30 p.m.