frowid {timeplyr}R Documentation

Fast grouped row numbers

Description

Very fast row numbers by group.

Usage

frowid(x, ascending = TRUE)

Arguments

x

A vector, data frame or GRP object.

ascending

When ascending = TRUE the row IDs are in increasing order. When ascending = FALSE the row IDs are in decreasing order.

Details

frowid() is like data.table::rowid() but uses an alternative method for calculating row numbers. When x is a collapse GRP object, it is considerably faster. It is also faster for character vectors.

Value

An integer vector of row IDs.

See Also

row_id add_row_id

Examples

library(timeplyr)
library(dplyr)
library(data.table)
library(nycflights13)

# Simple row numbers
head(row_id(flights))
# Row numbers by origin
head(frowid(flights$origin))
head(row_id(flights, origin))

# Fast duplicate rows
head(frowid(flights) > 1)

# With data frames, better to use row_id()
flights %>%
  add_row_id() %>% # Plain row ids
  add_row_id(origin, dest, .name = "grouped_row_id") # Row IDs by group


[Package timeplyr version 0.8.1 Index]