to_fixed_digits: Format Numeric Columns to Fixed Digits

View source: R/wrangling-utils.R

to_fixed_digitsR Documentation

Format Numeric Columns to Fixed Digits

Description

This function formats specified numeric columns in a data frame to a fixed number of decimal places.

Usage

to_fixed_digits(data, ..., .digits = 3)

Arguments

data

A data frame or tibble containing the columns to format.

...

<tidy-select> Columns to apply the fixed digit formatting to. If no columns are specified, all numeric columns are selected.

.digits

An integer specifying the number of decimal places to format to. Default is 3.

Details

Tibble data frames display numeric values to a certain number of significant figures, determined by the pillar.sigfig option. Sometimes it may be useful or necessary to see values to a fixed number of digits. This can be accomplished with num. This function is a convenience function that applies num to all, or a specified subset, of the numeric vectors in a tibble.

Value

A data frame with the selected numeric columns formatted to the specified number of decimal places.

Examples

# Format all numeric columns to 3 decimal places
mtcars_df <- tibble::as_tibble(mtcars)
to_fixed_digits(mtcars_df)

# Format columns mpg to qsec to 3 decimal places
to_fixed_digits(mtcars_df, mpg:qsec)

# Format specific columns to 2 decimal places
to_fixed_digits(mtcars_df, mpg, hp, .digits = 2)


mark-andrews/psyntur documentation built on Nov. 18, 2024, 7:17 a.m.