Learn R Programming

fastplyr (version 0.2.0)

group_id: Fast group and row IDs

Description

These are tidy-based functions for calculating group IDs and row IDs.

  • group_id() returns an integer vector of group IDs the same size as the data.

  • row_id() returns an integer vector of row IDs.

The add_ variants add a column of group IDs/row IDs.

Usage

group_id(data, order = TRUE, ascending = TRUE, as_qg = FALSE)

add_group_id( data, ..., order = TRUE, ascending = TRUE, .by = NULL, .cols = NULL, .name = NULL, as_qg = FALSE )

# S3 method for data.frame add_group_id( data, ..., order = df_group_by_order_default(data), ascending = TRUE, .by = NULL, .cols = NULL, .name = NULL, as_qg = FALSE )

row_id(data, ascending = TRUE)

# S3 method for GRP row_id(data, ascending = TRUE)

add_row_id(data, ..., ascending = TRUE, .by = NULL, .cols = NULL, .name = NULL)

# S3 method for data.frame add_row_id(data, ..., ascending = TRUE, .by = NULL, .cols = NULL, .name = NULL)

Value

An integer vector.

Arguments

data

A data frame or vector.

order

Should the groups be ordered? THE PHYSICAL ORDER OF THE DATA IS NOT CHANGED.
When order is TRUE (the default) the group IDs will be ordered but not sorted.

If FALSE the order of the group IDs will be based on first appearance.

ascending

Should the group order be ascending or descending? The default is TRUE.
For row_id() this determines if the row IDs are increasing or decreasing.
NOTE - When order = FALSE, the ascending argument is ignored. This is something that will be fixed in a later version.

as_qg

Should the group IDs be returned as a collapse "qG" class? The default (FALSE) always returns an integer vector.

...

Additional groups using tidy data-masking rules.
To specify groups using tidyselect, simply use the .by argument.

.by

Alternative way of supplying groups using tidyselect notation.

.cols

(Optional) alternative to ... that accepts a named character vector or numeric vector. If speed is an expensive resource, it is recommended to use this.

.name

Name of the added ID column which should be a character vector of length 1. If .name = NULL (the default), add_group_id() will add a column named "group_id", and if one already exists, a unique name will be used.