round_something: The function round_something() does numerical rounding with a...

Description Usage Arguments Value Examples

View source: R/guf.R

Description

The function round_something() does numerical rounding with a specified number of decimals. The 'something' will typically be a data.frame with mixed column types, of which the numerical columns must be rounded. This function makes that easier: all non-numerical columns are left in place, the numerical columns are rounded. Columns that are character but can be interpreted as numerical are first converted to numerical, and then rounded.

Usage

1
round_something(something, decimals = 0)

Arguments

something

The object of which the numbers need to be rounded. Can be a numerical or character vector, a matrix, a data.frame or a list containing these elements.

decimals

An integer specifying how many decimal points the result must contain.

Value

The same structure as used for the input of 'something', but then with rounded numbers (where applicable).

Examples

1
2
3
4
5
6
my_DF = data.frame(A=c(1.111,2.22,3.3,4), B=c("A", "Bb", "Ccc", "Dddd"), row.names=c(1,2,3,4))
round_something(my_DF)
round_something(my_DF, 2)
my_list = list(A=c(1.111,2.22,3.3,4), B=c("A", "Bb", "Ccc", "Dddd"))
round_something(my_list)
round_something(my_list, 2)

guf documentation built on March 26, 2020, 5:51 p.m.