Hi, I used str() on my data set:
$ X1 : num 1 1 0 1 1 1 1 1 1 1 ... $ X2 : num 0 1 0 2 1 2 0 2 2 0 ... $ X3 : Factor w/ 4 levels "0","1","2","NA": 2 1 3 1 1 1 1 1 1 3 ... .... The difference to your str() output is that in your case NA columns are "num" columns and in my case they are Factors. That's prob. why it replaces the NAs with 4 after applying data.matrix. I use the package xlsx to read the data in as an excel file. Cheers -- View this message in context: http://r.789695.n4.nabble.com/convert-data-frame-to-matrix-NA-factor-problem-tp2288828p2288887.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list 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.