Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The level order can be specified explicitly by passing the
factor to factor() and
specifying levels. In this example,
we’ll create a factor that initially has the wrong ordering:
# By default, levels are ordered alphabeticallysizes<-factor(c("small","large","large","small","medium"))sizessmall large large small medium Levels: large medium small# Change the order of levelssizes<-factor(sizes,levels=c("small","medium","large"))sizessmall large large small medium Levels: small medium large
The order can also be specified with levels when the factor is first
created.