[R] confusion on levels() function, and how to assign a wanted order to factor levels, intentionally?

Zeljko Vrba zvrba at ifi.uio.no
Tue Jun 16 10:01:26 CEST 2009


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 <- factor(d$population, levels=c("YXPy01", "KMPy01", "YLPy01", ..))

[just to avoid any confusion: you have to spell out all levels instead of using
'..'; R will not automagically guess them.]




More information about the R-help mailing list