Skip to content
Prev 173142 / 398503 Next

Changing factor to numeric

From ?factor:

The interpretation of a factor depends on both the codes and the 
"levels" attribute. Be careful only to compare factors with the same set 
of levels (in the same order). In particular, as.numeric applied to a 
factor is meaningless, and may happen by implicit coercion. To transform 
a factor f to its original numeric values, as.numeric(levels(f))[f] is 
recommended and slightly more efficient than as.numeric(as.character(f)).

Uwe Ligges
ojal john owino wrote: