Required packages
This snippet only requires base
. You do not need to load any package.
Snippet
To round a numerical value, use round()
.
round(54.87)
Code language: R (r)
Dive deeper
Number of digits
You can specify how many digits you want with digits
. If digits
is not specified, round()
defaults to zero digits.
round(54.87, digits = 1)
Code language: R (r)
Variables
You can use variables, providing they are of type numeric:
x <- 54.87
round(x)
Code language: R (r)