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

Overview

In R, the is.factor() function is used to return a logical value, TRUE or FALSE, indicating whether an argument passed to it is of type factor or not.

Syntax

is.factor(X)

Parameter value

This function takes a single parameter value, X, which represents any R object.

Return value

This function returns a TRUE or FALSE value.

Example

# creating different R objects
Height <- factor(c("Tall", "Average", "Short"))
my_function <- function() {
print("Hello World!")
}
# checking if they are factors or not
is.factor(Height)
is.factor(my_function)

Explanation

  • Line 2: We use the factor() function to create an R object, Height.
  • Line 3: We use the function() function to create another R object, myfunction.
  • Line 8: We use the is.factor() function to check if the object Height is a factor or not.
  • Line 9: We use the is.factor() function to check if the object myfunction is a factor or not.

    Free Resources