group_split: Split data frame by groups

View source: R/group-split.R

group_splitR Documentation

Split data frame by groups



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

  • It uses the grouping structure from group_by() and therefore is subject to the data mask

  • It does not name the elements of the list based on the grouping as this only works well for a single character grouping variable. Instead, use group_keys() to access a data frame that defines the groups.

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.


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



A tbl.


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


Should the grouping columns be kept?


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.


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()


ir <- iris %>% group_by(Species)


dplyr documentation built on Nov. 17, 2023, 5:08 p.m.