is.ordered() Function in R Programming Example
Example 1: Demonestration of R – is.ordered() Function
R
# 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:
R
# 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
Check if a Factor is an Ordered Factor in R Programming – is.ordered() Function
is.ordered() function in R Programming Language is used to check if the passed factor is an ordered factor.
Syntax: is.ordered(factor)
Parameters:
- factor: Factor to be checked