Rounding Up, Down, and to a Specific Number of Digits in R
Overview
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()
andsignif()
functions keep digits, butround()
focuses on the digits below the decimal point, whereassignif()
is concerned with the entire number. Usually,round()
is sufficient, but if one desires a clean alignment of results, thesignif()
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.