Convert an Unordered Factor to an Ordered Factor in R Programming – as.ordered() Function
Last Updated :
04 Jun, 2020
as.ordered()
function in R Language takes an unordered factor as argument and converts it into an ordered factor.
Syntax: as.ordered(factor)
Parameters:
factor: Unordered Factor to be converted
Example 1:
x< - c( "North" , "North" , "East" , "West" )
Directions < - factor(x)
as.ordered(Directions)
|
Output:
[1] North North East West
Levels: East < North < West
Example 2:
size = c( "small" , "large" , "large" , "small" ,
"medium" , "large" , "medium" , "medium" )
sizes < - ordered(c( "small" , "large" , "large" ,
"small" , "medium" ))
as.ordered(sizes)
|
Output:
[1] small large large small medium
Levels: large < medium < small
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...