group: Group by one or more variables

group_byR Documentation

Group by one or more variables

Description

Most data operations are done on groups defined by variables. group_by will group the data.table by selected variables (setting them as keys), and arrange them in ascending order. group_exe could do computations by group, it receives an object returned by group_by.

Usage

group_by(.data, ...)

group_exe(.data, ...)

groups(x)

ungroup(x)

Arguments

.data

A data.table

...

For group_by:Variables to group by. For group_exe:Any data manipulation arguments that could be implemented on a data.table.

x

A data.table

Details

For mutate and summarise, it is recommended to use the innate "by" parameter, which is faster. Once the data.table is grouped, the order is changed forever.

groups() could return a character vector of specified groups.

ungroup() would delete the keys in data.table.

Value

A data.table with keys

Examples

a = as.data.table(iris)
a
a %>%
  group_by(Species) %>%
  group_exe(
    head(3)
  )
groups(a)
ungroup(a)
groups(a)

tidyft documentation built on Jan. 9, 2023, 1:27 a.m.