[R] Basic factor question.

rkevinburton at charter.net rkevinburton at charter.net
Sat Aug 2 23:48:48 CEST 2008


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] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
[16] <NA> <NA> <NA> <NA> <NA>
Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

So why all of the NA? What happend to 'a'. 'b', etc.? I was expecting a=1, b=2, c=3 etc.

I am missing something. Please help with my understanding. 

Keviin



More information about the R-help mailing list