[R] excluding factor levels with read.table() and colClasses=
Peter Tait
petertait at sympatico.ca
Fri Mar 17 03:57:53 CET 2006
Hi,
I did try the code with the na.strings option but it did not work. The
factor bmicat still contains "NA" as one of its levels. Can read.table()
exclude "NA" values from the variables it reads from test.txt? If not
what is the best way to remove these unwanted levels from a factor when
programming a function?
Thanks
Peter
>inrange<-read.table("C://test.txt", header=T, sep="|",
na.strings=c("NA","."), colClasses=c(bmicat="factor"))
>summary(inrange)
bmicat
<23 : 294
>28 :1482
23-28 :1043
NA : 13
> levels(bmicat)
[1] "<23 " ">28 " "23-28 " "NA "
> contrasts(bmicat)
>28 23-28 NA
<23 0 0 0
>28 1 0 0
23-28 0 1 0
NA 0 0 1
>
More information about the R-help
mailing list