What is the is.integer() function in R?

Overview

In R, the is.integer() function is used to test if a given R object is of type integer or not.

Syntax

is.integer(x)
Syntax for the is.integer() function in R

Parameter

This function takes a single parameter value, x, representing any R object to be tested.

Return value

This function returns TRUE if the object is an integer. Otherwise, it returns FALSE.

Example

# creating R objects
my_doubles1 <- c(1.1 , 2.2 , 3.3, 4.4 )
my_doubles2 <- c(1 , 2 , 3 , 4 )
my_integers <- c(1L , 2L , 3L , 4L )
my_random <- c(1L , 2L , 3L , 4 )
#implementing the is.integer() function
is.integer(my_doubles1)
is.integer(my_doubles2)
is.integer(my_integers)
is.integer(my_random)

Explanation

  • Lines 2–5: We create different R objects containing numerical values.
  • Lines 9–12: We use the is.integer() function to check to see if each of the objects is an integer type or not.
Note: The object my_integers is the only integer type object among all of them. Interestingly, the object my_doubles2 is not an integer object but a double.

Free Resources