[R] plot is not keeping the order of variable
dieter.menne at menne-biomed.de
Mon Feb 22 08:30:55 CET 2010
Peter Dalgaard wrote:
> d <- data.frame(f=c("rare", "medium","well-done"))
> #To get the cast in order of appearance, this can be used:
> > d$f <- factor(d$f, levels=unique(d$f))
> > d$f
>  rare medium well-done
> Levels: rare medium well-done
.. which caused some head-scratching from me, because it made me believe
there was some hidden Kopenhagen-factor conserving the original order.
To protect the innocent: for the more general case, unique() does not help.
levs = c("rare", "medium","well-done")
d <- data.frame(f=sample(levs,10,TRUE))
d$f = factor(d$f, levels=unique(d$f))
d$f = factor(d$f, levels = levs)
View this message in context: http://n4.nabble.com/plot-is-not-keeping-the-order-of-variable-tp1563553p1564087.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help