Skip to contents

This function rounds (only) the numeric columns of a data.frame.

Usage

round_data.frame(df, digits = 0)

Arguments

df

[data.frame]
A data.frame.

digits

[integer(1) | NULL ]
The number of decimal places to be used.

Negative values are allowed, resulting in rounding to a power of ten.

Can be NULL to not round.

Value

A data.frame.

See also

Examples

df <- data.frame("label" = c("A", "B"), "number" = rnorm(10))
round_data.frame(df, digits = 1)
#>    label number
#> 1      A   -0.8
#> 2      B   -0.2
#> 3      A   -0.7
#> 4      B    2.2
#> 5      A    0.5
#> 6      B   -0.4
#> 7      A   -0.8
#> 8      B    0.5
#> 9      A   -1.1
#> 10     B    0.2