[R] knowing the code-number of factors in a vector

Ben Bolker bbolker at gmail.com
Sat Dec 4 05:07:40 CET 2010


Eduardo Klein <eklein <at> usb.ve> writes:


> I would like to know how R assigns the numeric code to a set of factors 
> in a vector. 

  [snip]

> 

  It is indeed alphabetical by default.  To get it in order of
appearance you could do something like

set.seed(1001)
x <- sample(letters[1:5],50,replace=TRUE)
f <- factor(x,levels=unique(x))



More information about the R-help mailing list