Learn R Programming

icesAdvice (version 2.1.1)

icesRound: ICES Rounding Method

Description

Round values according to the ICES Advice Technical Guidelines.

Usage

icesRound(x, percent = FALSE, sign = percent, na = "")

Arguments

x

the values to round.

percent

whether to format values with a percent suffix.

sign

whether to format values with a sign prefix.

na

what to return when x is NA.

Value

Rounded values as a noquote string vector, retaining trailing zeros.

References

ICES (2017) Rounding rules to be applied in ICES advice. 10.17895/ices.pub.3038ICES Advice Technical Guidelines 16.5.4.

See Also

signif rounds values to a specified number of significant digits.

icesAdvice-package gives an overview of the package.

Examples

Run this code
# NOT RUN {
icesRound(0.123456)
icesRound(0.2468)

## Formatted string or numeric
icesRound(1.0)
as.numeric(icesRound(1.0))

## Percent, sign, NA
icesRound(33.33, percent = TRUE)
icesRound(33.33, sign = TRUE)
icesRound(c(1, NA, 3))
icesRound(c(1, NA, 3), na = NA)

## Example from the ICES Technical Guidelines
Actual <- c(0.35776, 0.34665, 0.202, 0.12665, 0.001567, 0.002567, 0.013415,
            0.02315, 1.168, 2.15678)
Rounded <- icesRound(Actual)
print(data.frame(Actual = as.character(Actual), Rounded), row.names = FALSE)

## Continued example from Guidelines, now rounding percentages
Actual <- c(9.546, 10.546, 23.445, -1.482, -9.09, 0.51, 130.11, 584)
Rounded <- icesRound(Actual, percent = TRUE)
print(data.frame(Actual = as.character(Actual), Rounded), row.names = FALSE)

# }

Run the code above in your browser using DataLab