group_split | R Documentation |
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)
.tbl |
A tbl. |
... |
If |
.keep |
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.
Other grouping functions:
group_by()
,
group_map()
,
group_nest()
,
group_trim()
ir <- iris %>% group_by(Species)
group_split(ir)
group_keys(ir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.