Here, I have a one-dimensional integer space (consist of random intervals defined by their begin and end). I would like to select consequent integer intervals with specific intra-inter length.
An integer interval means a set of consecutive increasing integers, defined by a begin integer and an end integer. Some intervals in the initial set are totally included in others or partially overlapped with others.
I describe my question using the following dummy.
(1) the data (integer space with integer intervals defined by their begin and end) I have,
integer.space <- data.frame(
begin=c(1,5,6,15,31,51,102),
end =c(7,9,13,21,49,52,108)
)
(2) what I want is to select the consequent integer intervals with intra-length of 3 and inter-length of 2. and output the selected intervals as begin and end. In this selection, I would like to select more integer intervals as most as it could be.
begin, end\n
1,3\n
6,8\n
11,13\n
16,18\n
31,33\n
36,38\n
41,43\n
46,48\n
102,104\n
I would do this in several steps:
1) Reduce the integer.space to nonoverlapping intervals.
2) Create a collection of intervals, and shift them so that they start at start points of the disjoint pieces of the integer space:
3) Remove those that lie outside the integer space