rnd | R Documentation |
Round column values in a data frame.
rnd(x, cols, digits = 0, grep = FALSE, ...)
x |
a data frame. |
cols |
column names, or column indices. |
digits |
number of decimal places. |
grep |
whether |
... |
passed to |
A data frame similar to x
, after rounding columns cols
to the
number of digits
.
Provides notation that is convenient for modifying many columns at once.
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.
TAF-package
gives an overview of the package.
The icesAdvice package provides the icesRound
function to round
values for ICES advice sheets.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.