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
survey_count is similar, but calls
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") )
A tbl_svy object, as created by
(Optional) A variable to weight on (in addition to the survey weights,
which are always used). If left unspecified,
Whether to sort the results (defaults to
Name of count variable created (defaults to n). If the variable already exists, will add "n" to the end until it does not.
What types variation estimates to calculate, passed to
Variables to group by, passed to
When .drop = TRUE, empty groups are dropped, see
n already exists,
tally will use it as the weight, but
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.