library(survey)
library(dplyr)
data(api)
svy <- as_survey_design(apistrat, strata = stype, weights = pw)
svy
# Data manipulation verbs ---------------------------------------------------
filter(svy, pcttest > 95)
select(svy, starts_with("acs")) # variables used in survey design are automatically kept
summarise(svy, col.grad = survey_mean(col.grad))
mutate(svy, api_diff = api00 - api99)
# Group by operations -------------------------------------------------------
# To calculate survey
svy_group <- group_by(svy, dname)
summarise(svy, col.grad = survey_mean(col.grad),
api00 = survey_mean(api00, vartype = "ci"))
Run the code above in your browser using DataLab