Skip to content
Related Articles

Related Articles

Improve Article

Check if a Factor is an Ordered Factor in R Programming – is.ordered() Function

  • Last Updated : 04 Jun, 2020

is.ordered() function in R Language is used to check if the passed factor is an ordered factor.

Syntax: is.ordered(factor)

Parameters:
factor: Factor to be checked

Example 1:




# Creating a vector 
x<-c("female", "male", "male", "female"
  
# Converting vector into factor
gender <- factor(x)
  
# Using is.ordered() Function
# to check if a factor is ordered
is.ordered(gender)

Output:

[1] FALSE

Example 2:




# creating vector size 
size = c("small", "large", "large", "small",  
         "medium", "large", "medium", "medium")   
sizes <- ordered(c("small", "large", "large"
                   "small", "medium")) 
    
# ordering the levels 
sizes <- ordered(sizes, levels = c("small", "medium", "large"))     
  
# Checking if the factor is ordered
# using is.ordered() function
is.ordered(sizes)

Output:

[1] TRUE
My Personal Notes arrow_drop_up
Recommended Articles
Page :