Open In App

Checking if the Object is a Factor in R Programming – is.factor() Function

Improve
Improve
Like Article
Like
Save
Share
Report

is.factor() function in R Language is used to check if the object passed to the function is a Factor or not. It returns a boolean value as output.

Syntax: is.factor(Object)

Parameters:
Object: Object to be checked

Example 1:




# Creating a vector 
x<-c("female", "male", "male", "female"
  
# Converting the vector x into a factor named gender 
gender<-factor(x) 
   
# Using is.factor() Function
is.factor(gender)


Output:

[1] TRUE

Example 2:




# Creating a vector 
x<-c("female", "male", "male", "female"
  
# Converting the vector x into a factor named gender 
gender<-factor(x) 
   
# Using is.factor() Function
is.factor(x)


Output:

[1] FALSE

Last Updated : 04 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads