[R] colClasses: supressed 'NA'

Anupam Tyagi AnupTyagi at yahoo.com
Tue Sep 26 21:12:56 CEST 2006


Hi,

The colClasses seem to be supressing 'NA' vlaues. How do I fix this?

R script and first 5 lines of output is below.

File "test2.dat" has blanks that are read as "NA" when I do not use
'colClasses', but as blanks when I use 'colClasses'.

temp.df <- read.fwf("test2.dat", width=c(10,1,1,1,1,2,2,3,3,1),  
col.names=c("psu","losewt","maintain","fewcal","phyact","age","income","weight",
"wtdesire","gender"),
colClasses=c("factor","factor","factor","factor","factor","numeric","factor",
"numeric","numeric","factor"),
nrows=270000, comment.char="")

temp.df
           psu losewt maintain fewcal phyact age income weight wtdesire gender
1   2003009323      2        2                52     05    220      220      1
2   2003005181      2        1      2      2  58     08    165      145      2
3   2003015942      2        1      4      1  76     05    142      130      2
4   2003011406      2        1      3      1  43     03    110      110      2
5   2003006786      1               4      1  49     06    178      145      2

? why am I not getting missing values when I use 'colClasses'?



More information about the R-help mailing list