I need a function (bespoke or from a package) that can filter a numeric vector based on whether the number is an integer or not.
So in the following vector
vec <- c(1.0, 5.0, 5.3, 10.0, 2.5)
I would want it to come out
integerFunction(vec)
[1] TRUE TRUE FALSE TRUE FALSE
I know R has special classes for numeric and integers but that is not what I am talking about. I need to find integers within a numeric class vector (i.e. where the value after the decimal is greater than 0)
>Solution :
You may try using floor
integerFunction <- function(x) {
x - floor(x) == 0
}
integerFunction(c(1.0, 5.0, 5.3, 10.0, 2.5))
[1] TRUE TRUE FALSE TRUE FALSE