Rounding Numbers

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

# round up to the nearest integer
ceiling(3.14159)
[1] 4
# round down to the nearest integer
floor(3.14159)
[1] 3
# cut off everything after the decimal point
trunc(3.14159)
[1] 3
# round the number to the third decimal place
round(3.14159, digits = 3)
[1] 3.142
# round to five significant digits
signif(3.14159, digits = 5)
[1] 3.1416