Learn R Programming

icesTAF (version 3.6.0)

rnd: Round Columns

Description

Round column values in a data frame.

Usage

rnd(x, cols, digits = 0, grep = FALSE, ...)

Value

A data frame similar to x, after rounding columns cols to the number of digits.

Arguments

x

a data frame.

cols

column names, or column indices.

digits

number of decimal places.

grep

whether cols is a regular expression.

...

passed to grep().

See Also

round is the underlying function used to round numbers.

grep is the underlying function used to match column names if grep is TRUE.

div is a similar function that divides columns with a common number.

icesTAF-package gives an overview of the package.

The icesAdvice package provides the icesRound function to round values for ICES advice sheets.

Examples

Run this code
# With rnd() we no longer need to repeat the column names:

m <- mtcars
m[c("mpg","disp","qsec")] <- round(m[c("mpg","disp","qsec")])
m <- rnd(m, c("mpg","disp","qsec"))

# The x1/x2/x3/x4 approaches are equivalent:

x1 <- rnd(summary.taf, c("Rec","Rec_lo","Rec_hi",
                         "TSB","TSB_lo","TSB_hi",
                         "SSB","SSB_lo","SSB_hi",
                         "Removals","Removals_lo","Removals_hi"))
x1 <- rnd(x1, c("Fbar","Fbar_lo","Fbar_hi"), 3)

x2 <- rnd(summary.taf, "Rec|TSB|SSB|Removals", grep=TRUE)
x2 <- rnd(x2, "Fbar", 3, grep=TRUE)

x3 <- rnd(summary.taf, "Fbar", grep=TRUE, invert=TRUE)
x3 <- rnd(x3, "Fbar", 3, grep=TRUE)

# Less reliable in scripts if columns have been added/deleted/reordered:

x4 <- rnd(summary.taf, 2:13)
x4 <- rnd(x4, 14:16, 3)

Run the code above in your browser using DataLab