Skip to content
Prev 26084 / 398502 Next

Warning: as.numeric reorders factor data

On Sun, 8 Dec 2002, Bud Gibson wrote:

            
Well, the help page for as.numeric says

     `as.numeric' for factors yields the codes underlying the factor
     levels, not the numeric representation of the labels.
Yes it is. It might have been better if at the dawn of time codes() had
been defined to do what as.numeric does and as.numeric to do what you
expect.   However, it's not completely obvious: what should as.numeric do
with a factor of postal codes whose levels are "3163" "90210" and "OX1 3DP"?
Because when you have more than one `by' variable in aggegrate it needs to
make a factor of the combined levels, which it does by pasting them
together as characters.
It might be worth help(aggregate) mentioning that the variables are turned
into factors.

	-thomas