[R] svytable and na's
Thomas Lumley
tlumley at uw.edu
Sat May 21 00:00:05 CEST 2011
On Fri, May 20, 2011 at 7:54 PM, Manderscheid Katharina
<Katharina.Manderscheid at unilu.ch> wrote:
> hi thomas
>
> thanks for your reply.
> in the documentation of svytable, the argument na.rm=T is mentioned.
No, it isn't. The page says
Usage
## S3 method for class 'survey.design':
svytable(formula, design, Ntotal = NULL, round = FALSE,...)
## S3 method for class 'svyrep.design':
svytable(formula, design, Ntotal = sum(weights(design, "sampling")),
round = FALSE,...)
There *is* an na.rm= argument to svychisq(), which is documented on
the same help page.
>
> however, last night i figured out what went wrong in my tabulation: i had a dataset which i attached and then defined the missing values - of course they were not stored in the data set.
>
> attach(data)
> vote[vote=="Don't know"|vote=="Refusal"]<-NA
> detach(data)
>
Yes, that's why attach() is usually a bad idea -- it's very easy to
get confused that way.
> or is there a way to define factor levels as na directly in an svydesign-object?
>
>
You can use update()
design <- update(design, vote=ifelse( vote %in% c("Don't
Know","Refusal"), NA, vote))
-thomas
--
Thomas Lumley
Professor of Biostatistics
University of Auckland
More information about the R-help
mailing list