Skip to contents

The trm_ints function trims ints in dataset x based on overlaps with ints in dataset y. It splits ints in x at the boundaries of overlaps with y, removes unwanted ints, and returns the resulting ints. Optionally, the output can be ordered by start and end points.

Usage

trm_ints(x, y, .x_start, .x_end, .y_start, .y_end, ..., .gap = 0, order = TRUE)

Arguments

x

A data frame containing the primary ints to be trimmed.

y

A data frame containing the ints used to trim x.

.x_start

The column name in x representing the start of the ints.

.x_end

The column name in x representing the end of the ints.

.y_start

The column name in y representing the start of the ints.

.y_end

The column name in y representing the end of the ints.

...

Additional columns to group by when calculating overlaps and trimming ints.

.gap

The gaps left when ints are trimmed. Default is 0.

order

A logical value indicating whether to order the resulting ints by start and end points. Default is TRUE.

Value

A data.table containing the trimmed ints from x, with columns for start, end, and any grouping variables.

Details

If x and y contains overlapping ints you may get unexpected results. Please use merge_ints if required.

Examples

x <- data.frame(
  id = c(1, 1, 2, 2),
  start = c(1, 5, 2, 6),
  end = c(4, 8, 5, 9)
)

y <- data.frame(
  id = c(1, 2),
  start = c(2, 4),
  end = c(6, 7)
)

result <- trm_ints(x, y, start, end, start, end, id)
print(result)
#>       id start   end
#>    <num> <num> <num>
#> 1:     1     1     2
#> 2:     1     6     8
#> 3:     2     2     4
#> 4:     2     7     9