The neg_ints function calculates negative ints (gaps) between positive ints in a dataset.
It is useful for identifying gaps in time-based or sequential data where ints are defined by
start and end points. The function allows for the specification of lower and upper bounds, as well
as a gap size between ints.
Arguments
- .data
A data frame or tibble containing the interval data.
- .start
The column name in
.datarepresenting the start of the ints.- .end
The column name in
.datarepresenting the end of the ints.- ...
Additional columns to group by when calculating negative ints.
- .lower
(Optional) The column name or value representing the lower bound for the ints. If
NULL, no lower bound is applied.- .upper
(Optional) The column name or value representing the upper bound for the ints. If
NULL, no upper bound is applied.- .gap
(Optional) The size of the gap between ints. Default is
1.
Value
A data frame or tibble containing both positive and negative ints, with columns for
start, end, lower bound, upper bound, and interval type (int_type).
Details
The function calculates negative ints by identifying gaps between positive ints in the dataset.
If
.loweris provided, the function ensures that the negative ints do not fall below the specified lower bound.If
.upperis provided, the function ensures that the negative ints do not exceed the specified upper bound.The function groups the data by the columns specified in
...to calculate ints within each group.The
int_typecolumn is added to the output to distinguish between positive ("pos") and negative ("neg") ints.
If .data contains overlapping ints you may get unexpected results. Please use merge_ints if required.
Examples
data <- data.frame(
id = c(1, 1, 2, 2),
start = c(1, 5, 2, 6),
end = c(3, 7, 4, 8)
)
result <- neg_ints(data, start, end, id, .gap = 1)
print(result)
#> id start end
#> <num> <num> <num>
#> 1: 1 4 4
#> 2: 2 5 5
