Skip to content
Prev 26069 / 398502 Next

Warning: as.numeric reorders factor data

Thanks for the clarification.  It's nice to know that there is some 
systematicity to the behavior.

Is this documented anywhere?  I did look at the help for as.numeric, and 
it makes no mention that it is coercing factors based on their level. 
 This may be obvious to those deeply immersed in R and its machinations, 
but to those who think the number they see on the screen should just 
become a number when it is coerced to one, it is disconcerting.

Further, if I just factor the same vector, and then coerce it back to 
numeric, the order I would have expected is preserved.  I did not report 
that test because it seemed irrelevant.  Why isn't aggregate just doing 
that?

My cut is that there should be some warning in the documentation, 
perhaps in aggregate, about the specific assumptions used in making 
implicit transformations and what one can expect.
Peter Dalgaard BSA wrote: