Learn R Programming

miceadds (version 1.5-0)

round2: RUtilities: Rounding DIN 1333 (Kaufmaennisches Runden)

Description

This is a rounding function which rounds up for all numbers according to the rule of 'kaufmaennisches Runden' (DIN 1333).

Usage

round2(vec, digits = 0)

Arguments

vec
Numeric vector
digits
Number of digits after decimal fort rounding

Value

  • Vector with rounded values

Examples

Run this code
#*** EXAMPLE 1
vec <- c( 1.5 , 2.5 , 3.5 , 1.51 ,  1.49)
vec
round(vec)
round2(vec)
  ##   > vec
  ##   [1] 1.50 2.50 3.50 1.51 1.49
  ##   > round(vec)
  ##   [1] 2 2 4 2 1
  ##   > round2(vec)
  ##   [1] 2 3 4 2 1

#*** EXAMPLE 2
vec <- - c( 1.5 , 2.5 , 3.5 , 1.51 ,  1.49)
vec
round(vec)
round2(vec)
  ##   > vec
  ##   [1] -1.50 -2.50 -3.50 -1.51 -1.49
  ##   > round(vec)
  ##   [1] -2 -2 -4 -2 -1
  ##   > round2(vec)
  ##   [1] -2 -3 -4 -2 -1

#*** EXAMPLE 3
vec <- c(8.4999999 , 8.5 , 8.501 , 7.4999999 , 7.5 , 7.501 )
round(vec)
round2( vec )
round2( vec , digits=1)
round2( -vec )
  ##   > round(vec)
  ##   [1] 8 8 9 7 8 8
  ##   > round2( vec )
  ##   [1] 8 9 9 7 8 8
  ##   > round2( vec , digits=1)
  ##   [1] 8.5 8.5 8.5 7.5 7.5 7.5
  ##   > round2( -vec )
  ##   [1] -8 -9 -9 -7 -8 -8

Run the code above in your browser using DataLab