Hi!
As Ben Bolker told you already, the levels are alphabetically ordered by
default.
When you print rfactor, the last line shows you the different levels, in
the saved order.
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
Eduardo Klein 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)
It seems to be dependent upon the the character ("assigned alphabetically")
which I found out by manually changing the order of appearance of the
characters in rfactor; the colour would stick to the character "a", whether
this appears first in rfactor or not.
I as able to control the colours be
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
4 matches
Mail list logo