group_consecutive: Group sequences

Description Usage Arguments Value Examples

View source: R/group-consecutive.R

Description

Could be either increasing or decreasing sequences. The order in the vector matters. There's no ordering done during the computation.

The missing values aren't handled gracefully. Be careful if the input data has any missing values.

Usage

1
group_consecutive(x, .early_exit = TRUE)

Arguments

x

a numeric vector with a length of one.

.early_exit

exits function early if there're no consecutive numbers. This argument is mainly for benchmarking purposes. Default value is TRUE.

Value

A list with a number of groups. The vectors in the list elements are the vector indices, not values.

Examples

1
2
3
4
5
x <- c(16, 17, 18, 19, 100, 99, 98)
group_consecutive(x)
## missing one in the middle:
y <- c(seq(1, 3), seq(5, 8))
group_consecutive(y)

strboul/mmy documentation built on Sept. 24, 2021, 12:08 p.m.