group_split: Split data.frame by groups

Description Usage Arguments Details Value See Also Examples

View source: R/group_split.R

Description

group_split() works like base::split() but

Usage

1
2
3
group_split(.data, ..., .keep = TRUE)

group_keys(.data)

Arguments

.data

A data.frame.

...

Grouping specification, forwarded to group_by().

.keep

logical(1). Should the grouping columns be kept (default: TRUE)?

Details

Grouped data.frames:

The primary use case for group_split() is with already groups data.frames, typically a result of group_by(). In this case, group_split() only uses the first argument, the grouped data.frame, and warns when ... is used.

Because some of these groups may be empty, it is best paired with group_keys() which identifies the representatives of each grouping variable for the group.

Ungrouped data.frames:

When used on ungrouped data.frames, group_split() forwards the ... to group_by() before the split, therefore the ... are subject to the data mask.

Value

See Also

group_by()

Examples

1
2
3
4
5
6
7
# Grouped data.frames:
mtcars %>% group_by(cyl, am) %>% group_split()
mtcars %>% group_by(cyl, am) %>% group_split(.keep = FALSE)
mtcars %>% group_by(cyl, am) %>% group_keys()

# Ungrouped data.frames:
mtcars %>% group_split(am, cyl)

poorman documentation built on March 28, 2021, 5:05 p.m.