tidy_numbers: Tidy number columns in a dataframe

View source: R/tidy_tables.R

tidy_numbersR Documentation

Tidy number columns in a dataframe

Description

This function ‘tidies’ a dataframe's number columns by representing numbers as characters and equalising the number of digits. This is designed to support the inclusion of tables created in R in word processors.

Usage

tidy_numbers(.data, digits, ignore = TRUE)

Arguments

.data

A data.frame or a tibble.

digits

An integer or a vector of integers that define(s) the number of digits for numerical columns. If one integer is supplied, this is applied to all number columns; if a vector is supplied, vector elements are applied to number columns in the order given.

ignore

A logical value that defines whether or not to ignore the input to digits for any number columns that only comprise integers (see add_lagging_point_zero).

Details

This function does not currently support scientific notation.

Value

The function returns a data.frame or a tibble.

Author(s)

Edward Lavender

Examples

# Define an example dataframe
d <- data.frame(x = 1:3, y = c(0.1, 0, 1), z = c("a", "b", NA))
# Use three decimal places for all number columns
tidy_numbers(d, 3, ignore  = FALSE)
# Use three decimal places for all number columns with decimal places
tidy_numbers(d, 3)
# Specify the number of decimal places for each number  column
tidy_numbers(d, c(2, 3))

edwardlavender/prettyGraphics documentation built on Jan. 19, 2025, 2:47 p.m.