CInt() MS Access function to R

How can i write CInt() function equivalent in R? The challenging part is the rounding to nearest even number. It gives 0 for 0.5 and 2 for 1.5.

As the round function in R follows the same standard (IEC 60559) of rounding to even, you can just first round, and then use R's as.integer function. A function for that would look like this :slight_smile:

CInt <- function (x) {
  as.integer(round(x))
}

CInt(0.5)
#> [1] 0
CInt(1.5)
#> [1] 2

class(CInt(0.5))
#> [1] "integer"

Created on 2020-07-31 by the reprex package (v0.3.0)

1 Like

Thanks. Makes sense.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.