logo

Rounding Up, Down, and to a Specific Number of Digits in R 📂R

Rounding Up, Down, and to a Specific Number of Digits in R

Overview

20180531_232701.png

The ceiling() function performs rounding up, while the floor() function performs rounding down. These functions might seem unnecessary in R, which is often used for statistics, but they are surprisingly convenient for data handling.

Description

  • The trunc() function drops everything below the decimal point in a similar manner but returns a value closer to $0$.
  • Both the round() and signif() functions keep digits, but round() focuses on the digits below the decimal point, whereas signif() is concerned with the entire number. Usually, round() is sufficient, but if one desires a clean alignment of results, the signif() function is necessary.

If you want to change the number of digits across the entire project instead of adjusting numbers one by one with such functions, use the options() function. Writing the desired number of digits in the option digits will output all real numbers with that specified number of digits.