Analogous to tally
and count, calculates the survey weighted
count of observations. survey_tally
will call survey_total
empty (resulting
in the count of each group) or on wt
if it is specified (resulting in the
survey weighted total of wt
). survey_count
is similar, but calls group_by
before calculating the count and then returns the data to the original groupings.
survey_tally( x, wt, sort = FALSE, name = "n", vartype = c("se", "ci", "var", "cv") ) survey_count( x, ..., wt = NULL, sort = FALSE, name = "n", .drop = dplyr::group_by_drop_default(x), vartype = c("se", "ci", "var", "cv") )
x | A tbl_svy object, as created by |
---|---|
wt | (Optional) A variable to weight on (in addition to the survey weights,
which are always used). If left unspecified, |
sort | Whether to sort the results (defaults to |
name | Name of count variable created (defaults to n). If the variable already exists, will add "n" to the end until it does not. |
vartype | What types variation estimates to calculate, passed to
|
... | Variables to group by, passed to |
.drop | When .drop = TRUE, empty groups are dropped, see |
If n
already exists, tally
will use it as the weight, but count
will not.
library(survey) data(api) dstrata <- apistrat %>% as_survey_design(strata = stype, weights = pw) dstrata %>% group_by(awards) %>% survey_tally()#> # A tibble: 2 × 3 #> awards n n_se #> <fct> <dbl> <dbl> #> 1 No 2236. 216. #> 2 Yes 3958. 216.dstrata %>% survey_count(awards)#> # A tibble: 2 × 3 #> awards n n_se #> <fct> <dbl> <dbl> #> 1 No 2236. 216. #> 2 Yes 3958. 216.