# group_data: Grouping metadata In dplyr: A Grammar of Data Manipulation

## Description

• `group_data()` returns a data frame that defines the grouping structure. The columns give the values of the grouping variables. The last column, always called `.rows`, is a list of integer vectors that gives the location of the rows in each group. You can retrieve just the grouping data with `group_keys()`, and just the locations with `group_rows()`.

• `group_indices()` returns an integer vector the same length as `.data` that gives the group that each row belongs to (cf. `group_rows()` which returns the rows which each group contains). `group_indices()` with no argument is deprecated, superseded by `cur_group_id()`.

• `group_vars()` gives names of grouping variables as character vector; `groups()` gives the names as a list of symbols.

• `group_size()` gives the size of each group, and `n_groups()` gives the total number of groups.

See context for equivalent functions that return values for the current group.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ```group_data(.data) group_keys(.tbl, ...) group_rows(.data) group_indices(.data, ...) group_vars(x) groups(x) group_size(x) n_groups(x) ```

## Arguments

 `.data, .tbl, x` A data frame or extension (like a tibble or grouped tibble). `...` Use of `...` is now deprecated; please use `group_by()` first instead.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11``` ```df <- tibble(x = c(1,1,2,2)) group_vars(df) group_rows(df) group_data(df) group_indices(df) gf <- group_by(df, x) group_vars(gf) group_rows(gf) group_data(gf) group_indices(gf) ```

### Example output

```Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

filter, lag

The following objects are masked from ‘package:base’:

intersect, setdiff, setequal, union

character(0)
<list_of<integer>>
[]
 1 2 3 4

# A tibble: 1 x 1
.rows
<list<int>>
1         
 1 1 1 1
 "x"
<list_of<integer>>
[]
 1 2

[]
 3 4

# A tibble: 2 x 2
x       .rows
* <dbl> <list<int>>
1     1         
2     2         
 1 1 2 2
```

dplyr documentation built on June 19, 2021, 1:07 a.m.
{"ft_lang_label":"__label__en","ft_lang_prob":0.58762556,"math_prob":0.93027216,"size":1937,"snap":"2021-43-2021-49","text_gpt3_token_len":591,"char_repetition_ratio":0.14433523,"word_repetition_ratio":0.06369427,"special_character_ratio":0.3200826,"punctuation_ratio":0.14871795,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98479193,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-09T07:26:43Z\",\"WARC-Record-ID\":\"<urn:uuid:bfb6528b-eec5-47d7-b4a8-1f2f680772c8>\",\"Content-Length\":\"60861\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a5e9c57c-c89e-460d-9132-abce2c1cb7d7>\",\"WARC-Concurrent-To\":\"<urn:uuid:6ef6dbac-aa5b-45d1-9e36-85727a012b80>\",\"WARC-IP-Address\":\"51.81.83.12\",\"WARC-Target-URI\":\"https://rdrr.io/cran/dplyr/man/group_data.html\",\"WARC-Payload-Digest\":\"sha1:YCQT32LWYPK7OMEIX3ZDH35NCGQXRD4H\",\"WARC-Block-Digest\":\"sha1:YVBGFJHLCMO6EIEQR4OACXBWGJT3PWDQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363689.56_warc_CC-MAIN-20211209061259-20211209091259-00078.warc.gz\"}"}