[R] colClasses: supressed 'NA'
Uwe Ligges
ligges at statistik.uni-dortmund.de
Tue Sep 26 21:51:40 CEST 2006
Anupam Tyagi wrote:
> 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'.
Well, you say it should be a factor, hence " " is taken as a level.
Otherwise you have to specify na.string = " ".
Uwe Ligges
> 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'?
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
More information about the R-help
mailing list