1.5 Round Function
Rounding in R is different from SAS or MS-Excel.
round(0.5) # run yourself
round(1.5)
round(2.5)
= 1:10 - 0.5 ; x x
## [1] 0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5
round(x) # round to even number
## [1] 0 2 2 4 4 6 6 8 8 10
If you want ordinary rounding function, you can use Round function in math package.
Round
## function (x, digits = 0)
## {
## Sign = sign(x)
## Temp = abs(x)/10^(-digits)
## Temp = trunc(Temp + 0.5)
## Temp = Temp * 10^(-digits)
## return(Sign * Temp)
## }
## <bytecode: 0x000001e2a3e56950>
## <environment: namespace:math>
Round(1:10 - 0.5)
## [1] 1 2 3 4 5 6 7 8 9 10
Round(450, 2)
## [1] 450
Round(1.25, -1)
## [1] 0