How to remove ordering of the levels from factor variable in R?

Pulse picture Pulse · Jul 11, 2013 · Viewed 12.9k times · Source

The title says it all, I ordered a factor variable when I generated it, now I would like to remove the ordering and use it as an unordered factor variable. And another question, if I use my factor variable as a predictor in a regression does it make a difference to R if it is ordered (ordinal) or simple factor variable (categorical)?

Answer

Simon O'Hanlon picture Simon O'Hanlon · Jul 11, 2013

All you need is

x <- factor( x , ordered = FALSE )

e.g.

x <- factor( c(1,2,"a") , ordered = TRUE )
x
#[1] 1 2 a
#Levels: 1 < 2 < a

x <- factor( x , ordered = FALSE )
x
#[1] 1 2 a
#Levels: 1 2 a