Dear R-helpers,
I want to make a series of boxplots on several numeric univariates with two
group variables (species and population, population nested in species, and
with population as the X-axis). In order to get a proper order of the
individual populations in X-axis, I need to assign a wanted
Hi,
The way you do it actually renames the factors one after each other (it
replaces the values in the data frame, which is not what you want).
Have a look at this code:
test - data.frame(id=c(1,2,3), fac=c(lv1, lv2, lv3) )
levels(test$fac)
test$fac2 - factor(test$fac, levels=c(lv3, lv2, lv1))
On Tue, Jun 16, 2009 at 03:14:01PM +0800, Mao Jianfeng wrote:
levels(d$population)-c(YXPy01, KMPy01, YLPy01, GSPy02, BCPy01,
LJPy01, GYPt01, YLPd01, CYPd01, CYPd02, CYPd03, BXPd01,
NSPt01)
I'm not at home with factors myself, but maybe this will do the trick for
you:
d$population -
Hi Mao,
I am confused. And, I want to know how to assign a wanted order to factor
levels, intentionally?
You want ?relevel. Although the documentation leads one to think that it can
only be used to set a reference level, with the other levels being moved
down, presently it can in fact be
Hi,
I tend to use a slightly modified version of stats::relevel, (from an
old thread on this list),
relevel =
function (x, ref, ...)
{
lev - levels(x)
if (is.character(ref))
ref - match(ref, lev)
if (any(is.na(ref)))
stop('ref' must be an existing level)
nlev - length(lev)
Mark Difford wrote:
Hi Mao,
I am confused. And, I want to know how to assign a wanted order to factor
levels, intentionally?
You want ?relevel. Although the documentation leads one to think that it can
only be used to set a reference level, with the other levels being moved
down,
Commenting on this, is there a strong argument against modifying
relevel() to reorder more than one level at a time?
I started a topic a while back (recursive relevel,
https://stat.ethz.ch/pipermail/r-help/2009-January/184397.html) and I've
happily used the proposed change since then by
7 matches
Mail list logo