Skip to contents

This function groups overlapping ints based on its start and end. It assigns a unique group ID to each set of overlapping ints. Intervals are considered overlapping if the start of one interval is within the gap threshold of the end of another interval.

Usage

grp_ints(.data, .start, .end, ..., .gap = 1, .group_col = int_grp_id)

Arguments

.data

A data frame containing the interval data.

.start

The column name (unquoted) representing the start of the ints.

.end

The column name (unquoted) representing the end of the ints.

...

Additional columns to group by before identifying overlapping ints.

.gap

The maximum allowed gap between ints for them to be considered overlapping. Intervals are grouped if the start of one interval is less than or equal to the end of the previous interval plus the gap. Default is 1.

.group_col

The name of the column that will indicate the group ID for overlapping ints. Default is int_grp_id.

Value

A data.table with the original data and an additional column indicating the group ID for overlapping ints (the .group_id column).

Examples

if (FALSE) { # \dontrun{
data <- data.frame(
  id = 1:5,
  start = c(1, 2, 5, 10, 12),
  end = c(3, 4, 7, 11, 14)
)

# Group ints with a gap of 1
grp_ints(data, start, end, .gap = 1)
} # }