Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

group_by

Group a (survey) dataset by one or more variables.


Description

Most data operations are useful when done on groups defined by variables in the dataset. The group_by function takes an existing table (or svy_table) and converts it to a grouped version, where operations are performed "by group".

Arguments

.data

A tbl

...

variables to group by. All tbls accept variable names, some will also accept functions of variables. Duplicated groups will be silently dropped.

add

By default, when add = FALSE, group_by will override existing groups. To instead add to the existing groups, use add = TRUE

.dots

Used to work around non-standard evaluation. See vignette("nse", package = "dplyr") for details.

Details

See group_by for more information about grouping regular data tables.

On tbl_svy objects, group_by sets up the object for operations similar to those allowed in svyby.

See Also

group_by for information about group_by on normal data tables.

Examples

# Examples of svy_tbl group_by
library(survey)
data(api)
dstrata <- apistrat %>%
  as_survey_design(strata = stype, weights = pw) %>%
  group_by(stype)

  dstrata %>%
    summarise(api_diff = survey_mean(api00 - api99))

srvyr

'dplyr'-Like Syntax for Summary Statistics of Survey Data

v1.0.1
GPL-2 | GPL-3
Authors
Greg Freedman Ellis [aut, cre], Thomas Lumley [ctb], Tomasz Żółtak [ctb], Ben Schneider [aut, ctb], Pavel N. Krivitsky [ctb]
Initial release
2021-03-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.