Skip to content
Back to formatted view

Raw Message

Message-ID: <loom.20101204T050549-889@post.gmane.org>
Date: 2010-12-04T04:07:40Z
From: Ben Bolker
Subject: knowing the code-number of factors in a vector

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))