Learn R Programming

volker (version 3.2.0)

data_round: Round and format selected numeric columns

Description

Round and format specified numeric columns in a data frame to a fixed number of decimal places.

Usage

data_round(data, cols, digits)

Value

The input data frame, with the specified numeric columns rounded and formatted as character vectors.

Arguments

data

A data frame or tibble.

cols

A tidyselect expression specifying which columns to round (e.g., c(var1, var2) or starts_with("score")).

digits

Integer; number of decimal places to round.

Details

For each selected numeric column:

  • The column is rounded using round().

  • It is then formatted as a character vector with a fixed number of decimal places using sprintf().

  • Missing values (NA) are preserved as NA_character_.

  • Original non-essential attributes (except class and levels) are restored.