> On 27 Sep 2015, at 22:12 , Bert Gunter <bgunter.4...@gmail.com> wrote:
> 
>> 
>> Due to missing data, R originally classified each X and Y variable as a 
>> ‘factor’, subsequently changed to ‘numeric’ via ‘as.numeric’ command.
> 
> No.
> a) missing data will not cause numeric data to become factor. There's
> something wrong in the data from the beginning (as Thierry said)

Well, if you forget to tell R what the input code for missing is (na.strings if 
you use read.table), then that is de facto what happens: The whole column gets 
interpreted as character and subsequently converted to a factor. The fix is to 
_remember_ to tell R what missing value codes are being used.

> 
> b) If f is numeric data that is a factor, as.numeric(f) is almost
> certainly **not** the corrrect way to change it to numeric.

Amen... as.numeric(as.character(f)) if you must, but the proper fix is usually 
the above.

-pd

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to