Learn R Programming

acledR (version 0.1.0)

acled_rounding: Rounding function

Description

This function addresses some of the conflicts of rounding in R, especially when trying to round up.

Usage

acled_rounding(num, digits = 0)

Value

A rounded numeric value

Arguments

num

int. This is the number we are trying to round.

digits

int. Where do we want to round up. It accepts 0 (whole number), 1 (tenth place), 2 (hundredths), etc.

Details

This function is meant to address the problem of rounding in R where the approach is always round to even. The function is meant to round things following the simple rule. If the decimal is 5+ then round up, if not round down. With the 'digits' argument, one can set up the specificity of the rounding, 0= whole number, 1 = tenth place, 2=hundreds place, and so on.

Examples

Run this code
x1 <- 1.569
x2 <- 104.530
x3 <- 54.430
x4 <- 205.49999
acled_rounding(x1)
acled_rounding(x2)
acled_rounding(x3)
acled_rounding(x4)

Run the code above in your browser using DataLab