If you’ve done any statistical analysis, then you’ll know that getting and cleaning the data is a major step in any project. SAS does a pretty good job at this, and will complain if the data is not in the format you think it is. As for R, here’s an excerpt from the R FAQ:
7.10 How do I convert factors to numeric?
It may happen that when reading numeric data into R (usually, when reading in a file), they come in as factors. If f is such a factor object, you can use
to get the numbers back. More efficient, but harder to remember, is
In any case, do not call as.numeric() or their likes directly for the task at hand (as as.numeric() or unclass() give the internal codes).
As one of my favorite musicals says, “It ain’t no joke, that’s why it’s funny”. Maybe when you do an uncommon operation like reading in a file, your numbers will be silently converted into factors / categorical variables. Or maybe not. Ha ha. But certainly, don’t do anything silly like thinking as.numeric(f) would convert f into numbers you might want. Ha ha ha. Oh, and that “more efficient” way of doing things? It crashes if f was actually numeric to start with. Ha ha ha ha. Stop, you’re killing me! [or at least, my productivity].
To complete the joke, here’s an excerpt from the R manual:
In general, coercion from numeric to character and back again will not be exactly reversible, because of roundoff errors in the character representation.
That’s fair enough. It’s not as if you have a good reason for doing this, except perhaps when you’re reading numbers in from a file.