| group_collapse {timeplyr} | R Documentation |
Key group information
Description
Key group information
Usage
group_collapse(
data,
...,
order = TRUE,
sort = FALSE,
ascending = TRUE,
.by = NULL,
.cols = NULL,
id = TRUE,
size = TRUE,
loc = TRUE,
start = TRUE,
end = TRUE,
.drop = df_group_by_drop_default(data)
)
Arguments
data |
A data frame or vector. |
... |
Additional groups using tidy |
order |
Should the groups be ordered?
THE PHYSICAL ORDER OF THE DATA IS NOT CHANGED. |
sort |
Should the data frame be sorted by the groups? |
ascending |
Should groups be ordered in ascending order?
Default is |
.by |
Alternative way of supplying groups using |
.cols |
(Optional) alternative to |
id |
Should group IDs be added? Default is |
size |
Should group sizes be added? Default is |
loc |
Should group locations be added? Default is |
start |
Should group start locations be added? Default is |
end |
Should group end locations be added? Default is |
.drop |
Should unused factor levels be dropped? Default is |
Details
group_collapse() is similar to dplyr::group_data() but differs in 3 key regards:
The output tries to convey as much information about the groups as possible. By default, like
dplyr, the groups are ordered, but unlikedplyrthey are not sorted, which conveys information on order-of-first-appearance in the data. In addition to group locations, group sizes and start indices are returned.There is more flexibility in specifying how the groups are ordered and/or sorted.
-
collapseis used to obtain the grouping structure, which is very fast.
There are 3 ways to specify the groups:
Using
...which utilisestidydata-masking.Using
.bywhich utilisestidyselect.Using
.colswhich accepts a named character/integer vector.
Value
A tibble of unique groups and an integer ID uniquely identifying each group.
Examples
library(timeplyr)
library(dplyr)
iris <- dplyr::as_tibble(iris)
group_collapse(iris) # No groups
group_collapse(iris, Species) # Species groups
iris %>%
group_by(Species) %>%
group_collapse() # Same thing
# Group entire data frame
group_collapse(iris, .by = everything())