Message-ID: <4CF989E0.4010302@usb.ve>
Date: 2010-12-04T00:22:56Z
From: Eduardo Klein
Subject: knowing the code-number of factors in a vector
Hi,
I would like to know how R assigns the numeric code to a set of factors
in a vector. For example, I have a vector of 5 different factors in a
random order, and I want a color-coded plot by factors:
rfactor=as.factor(sample(letters[1:5], 50, replace=T))
rfactor
[1] c c c d b a b d d a a e e b b e c e e a a b b b a b a e a a b d b
b c a b b
[39] d c a e c d e d a a a a
Levels: a b c d e
x=rnorm(50)
boxplot(x~rfactor, col=1:5)
So, colors 1 to 5 are assigned to factors alphabetically (a-1, b-2, ...,
e-5), or by order of appearance (c-1, d-2, b-3, a-4, e-5)? It is
possible to control that?
Saludos, EKS
--
Eduardo Klein
Lab Sensores Remotos e
Instituto de Tecnolog?a y Ciencias Marinas
Universidad Sim?n Bol?var
Caracas, Venezuela
ph (58) (212) 906-3111 ext 6700
fax (58) (212( 906-3111 ext 6701