Skip to content
Prev 246146 / 398503 Next

Retrieving Factors with Levels Ordered

Berwin A Turlach <berwin <at> maths.uwa.edu.au> writes:
Thanks to Berwin for the very thorough explanation.
At a more pragmatic level, I find that

testdf$myfactor <-
factor(testdf$myfactor,levels=unique(as.character(testdf$myfactor)))

  generally works OK to reorder the factor levels into the order in
which they appear in the data set ...