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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

[1] FALSE

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

[1] TRUE
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.