Skip to content

Commit

Permalink
Updated reference for the R version from the 'round_half_up()' functi…
Browse files Browse the repository at this point in the history
…on in the janitor package, to the 'round5()' function in the cards package.
  • Loading branch information
muridaehsr committed Oct 21, 2024
1 parent 32c9977 commit a3e5a42
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Comp/r-sas_rounding.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ title: "R v SAS rounding"

**Rounding; R and SAS**

On comparing the documentation of rounding rules for both languages, it will be noted that the default rounding rule (implemented in the respective language's round() function) are different. Numerical differences arise in the knife-edge case where the number being rounded is equidistant between the two possible results. The round() function in SAS will round the number 'away from zero', meaning that 12.5 rounds to the integer 13. The round() function in Base R will round the number 'to even', meaning that 12.5 rounds to the integer 12. SAS does provide the rounde() function which rounds to even and the janitor package in R contains a function round_half_up() that rounds away from zero. In this use case, SAS produces a correct result from its round() function, based on its documentation, as does R. Both are right based on what they say they do, but they produce different results (Rimler, M.S. et al.).

As described in [R - Rounding](../R/rounding.html) and [SAS - Rounding](../SAS/rounding.html), `round()` in SAS and `round_half_up()` in R are incorrect in rare different cases. It may need to be considered when comparing results between SAS and R.
On comparing the documentation of rounding rules for both languages, it will be noted that the default rounding rule (implemented in the respective language's round() function) are different. Numerical differences arise in the knife-edge case where the number being rounded is equidistant between the two possible results. The round() function in SAS will round the number 'away from zero', meaning that 12.5 rounds to the integer 13. The round() function in Base R will round the number 'to even', meaning that 12.5 rounds to the integer 12. SAS does provide the rounde() function which rounds to even and the cards package in R contains a function round5() that rounds away from zero. In this use case, SAS produces a correct result from its round() function, based on its documentation, as does R. Both are right based on what they say they do, but they produce different results (Rimler, M.S. et al.).

As described in [R - Rounding](../R/rounding.html) and [SAS - Rounding](../SAS/rounding.html), `round()` in SAS and `cards::round5()` in R are incorrect in rare different cases. It may need to be considered when comparing results between SAS and R.

**References**

Expand Down

0 comments on commit a3e5a42

Please sign in to comment.