Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 92
4.3.7.2 Ordering Factors
ОглавлениеIn the example about creating a factor-object for feedback one will have noticed that the plotfunction does show the labels in alphabetical order and not in an order that for us – humans – would be logical. It is possible to coerce a certain order in the labels by providing the levels – in the correct order – while creating the factor-object.
feedback <- c(‘Good’,‘Good’,‘Bad’,‘Average’,‘Bad’,‘Good’) factor_feedback <- factor(feedback, levels=c(“Bad”,“Average”,“Good”)) plot(factor_feedback)
In Figure 4.2 on page 63 we notice that the order is now as desired (it is the order that we have provided via the attribute labels
in the function factor()
.