dfround: Round Variables in a Data Frame

View source: R/dfround.r

dfroundR Documentation

Round Variables in a Data Frame

Description

Function to round the numeric variables in a data frame.

Usage

dfround(x, digits, drop0=TRUE)

Arguments

x

a data frame.

digits

either a single integer or a numeric vector of the same length as there are columns in x.

drop0

logical (or a vector thereof) indicating if trailing zeros after the decimal mark should be removed (the default is TRUE).

Details

A simple convenience function to round the numeric variables in a data frame, possibly to different numbers of digits. Hence, digits can either be a single integer (which will then be used to round all numeric variables to the specified number of digits) or a numeric vector (of the same length as there are columns in x) to specify the number of digits to which each variable should be rounded.

Non-numeric variables are skipped. If digits is a vector, some arbitrary value (or NA) can be specified for those variables.

Note: When drop0=FALSE, then formatC is used to format the numbers, which turns them into character variables.

Value

Returns the data frame with variables rounded as specified.

Author(s)

Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org

Examples

dat <- dat.bcg
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat)
res <- rma(yi, vi, mods = ~ ablat + year, data=dat)
coef(summary(res))
dfround(coef(summary(res)), digits=c(2,3,2,3,2,2))

metafor documentation built on May 29, 2024, 7:44 a.m.