The 'levels' is supposed to be the order in which you want the factors
to be. You have specified levels=1:20 and there are no matching
values in letters[1:20], therefore NAs:
> x <- factor(letters[1:20], levels=letters[20:1])
> x
[1] a b c d e f g h i j k l m n o p q r s t
Levels: t s r q p o n
Kevin -
Read more closely "levels", being an optional vector of the values x
might have taken. You are saying x might have taken 1:20, and then
giving it the first 20 letters, which are not part of "the values x
might have taken".
Try:
x <- factor(letters[1:20])
levels(x)
x
vs.
y <- fact
Doing ?factor I get:
x a vector of data, usually taking a small number of distinct values.
levels an optional vector of the values that x might have taken. The default is
the set of values taken by x, sorted into increasing order.
So if I do:
factor(letters[1:20],level=seq(1:20)
[1]
3 matches
Mail list logo