tidy_numbers | R Documentation |
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.
tidy_numbers(.data, digits, ignore = TRUE)
.data |
A |
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 |
This function does not currently support scientific notation.
The function returns a data.frame
or a tibble
.
Edward Lavender
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.