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 > [1] 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. Dieter levs = c("rare", "medium","well-done") set.seed(4711) d <- data.frame(f=sample(levs,10,TRUE)) unique(d$f) d$f = factor(d$f, levels=unique(d$f)) levels(d$f) d$f = factor(d$f, levels = levs) levels(d$f) -- 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. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.