View source: R/wrangling-utils.R
to_fixed_digits | R Documentation |
This function formats specified numeric columns in a data frame to a fixed number of decimal places.
to_fixed_digits(data, ..., .digits = 3)
data |
A data frame or tibble containing the columns to format. |
... |
< |
.digits |
An integer specifying the number of decimal places to format to. Default is 3. |
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.
A data frame with the selected numeric columns formatted to the specified number of decimal places.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.