group_split {dplyr}R Documentation

Split data frame by groups

Description

[Experimental]

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

group_split() is primarily designed to work with grouped data frames. You can pass ... to group and split an ungrouped data frame, but this is generally not very useful as you want have easy access to the group metadata.

Usage

group_split(.tbl, ..., .keep = TRUE)

Arguments

.tbl

A tbl.

...

If .tbl is an ungrouped data frame, a grouping specification, forwarded to group_by().

.keep

Should the grouping columns be kept?

Value

A list of tibbles. Each tibble contains the rows of .tbl for the associated group and all the columns, including the grouping variables. Note that this returns a list_of which is slightly stricter than a simple list but is useful for representing lists where every element has the same type.

Lifecycle

group_split() is not stable because you can achieve very similar results by manipulating the nested column returned from tidyr::nest(.by =). That also retains the group keys all within a single data structure. group_split() may be deprecated in the future.

See Also

Other grouping functions: group_by(), group_map(), group_nest(), group_trim()

Examples

ir <- iris %>% group_by(Species)

group_split(ir)
group_keys(ir)

[Package dplyr version 1.1.4 Index]