Essentially a wrapper around round
, rather than truncate
, which is what as.integer
does. Internally, this is simply as.integer(floor(x + 0.5))
.
asInteger(x)
x | A numeric vector |
---|
An integer vector of length x
, rounded to zero decimal places
prior to as.integer
Values ending in .5
will be rounded up, whether positive or negative.
This is different than round
.
#> dbl int #> 1 -2.00 -2 #> 2 -1.75 -2 #> 3 -1.50 -1 #> 4 -1.25 -1 #> 5 -1.00 -1 #> 6 -0.75 -1 #> 7 -0.50 0 #> 8 -0.25 0 #> 9 0.00 0 #> 10 0.25 0 #> 11 0.50 1 #> 12 0.75 1 #> 13 1.00 1 #> 14 1.25 1 #> 15 1.50 2 #> 16 1.75 2 #> 17 2.00 2