round_numeric_cols: Round all numeric type columns in a data frame

Description Usage Arguments Value Examples

View source: R/round_numeric_cols.R

Description

Automatically applies 'round()' to all numeric columns in a data frame using 'dplyr::mutate_all()'. Column names are retained, the number of digits rounded to defaults to zero.

Usage

1
round_numeric_cols(.tbl, .digits = 0)

Arguments

.tbl

a tibble or data frame

.digits

integer indicating the number of decimal places to be used. See '?round' for more information.

Value

a tibble or data frame whose numeric columns are rounded

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(dplyr)

set.seed(1914)

example_tbl <- tibble(
  col_one   = runif(n = 10) * 100,
  col_two   = runif(n = 10) * 50,
  col_three = rep(c("a", "b", "c", "d", "e"), times = 2)
)

example_tbl

example_tbl %>% round_numeric_cols()

RobbyLankford/lankford documentation built on April 24, 2020, 7:37 p.m.