[R] problem with svyby and NAs (survey package)
A.F.Fenton at lse.ac.uk
A.F.Fenton at lse.ac.uk
Fri Apr 13 21:17:39 CEST 2012
> I'm trying to get the proportion "true" for dichotomous variable for
various
> subgroups in a survey.
Sorry, I'm new to the list, and just saw the advice about minimally
reproducible code. Here goes:
library(survey)
foo <- data.frame(id = 1:25,
weight = runif(25),
year = rep(2002:2006, 5),
problem = rnorm(25) > 0)
foo.dsn = svydesign(id=~id, weight=~weight, data=foo)
svyby(~problem, ~year, foo.dsn, svymean, na.rm=TRUE) # Fine
# One year is missing
foo[foo$year == 2004, "problem"] = NA
foo.dsn = svydesign(id=~id, weight=~weight, data=foo)
svyby(~problem, ~year, foo.dsn, svymean, na.rm=TRUE) # Error
thanks
alex
Please access the attached hyperlink for an important electronic communications disclaimer: http://lse.ac.uk/emailDisclaimer
More information about the R-help
mailing list