Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6942515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:01:47+00:00 2026-05-27T13:01:47+00:00

Here, I have a one-dimensional integer space (consist of random intervals defined by their

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:01:48+00:00Added an answer on May 27, 2026 at 1:01 pm

    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:

    intra <- 3
    inter <- 2
    intervals <- data.frame(begin=seq(from=min(integer.space$begin),to=max(integer.space$end),by=intra+inter))
    intervals$end <- intervals$begin + inter
    for (k in 2:nrow(integer.space)) {
      # overlaps the start of this component?
      shift <- (intervals$begin>integer.space$end[k-1]) & (intervals$begin<integer.space$begin[k]) 
      if (any(shift)) {
        shift.ind <- min(which(shift))
        intervals[shift.ind:nrow(intervals),] <- intervals[shift.ind:nrow(intervals),] + integer.space$begin[k] - intervals$begin[shift.ind]
      }
    }
    

    3) Remove those that lie outside the integer space

    goodbegins <- sapply(intervals$begin, function (x) { 
        any( (x>=integer.space$begin) & (x<=integer.space$end) )
      } )
    goodends <- sapply(intervals$end, function (x) { 
        any( (x>=integer.space$begin) & (x<=integer.space$end) )
      } )
    intervals <- intervals[goodbegins&goodends,]
    
    intervals
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New Programmer here. Trying space invaders. I have a 2 dimensional array of objects
I have a 49 space one dimensional array declared as int boardArray [49]; and
Here is my situation: I have one table that contains a list of drugs
so here's the problem I have one form, it outputs search results after submit,
here is the problem. I have one PC using VS2008 (SP1 ) and another
Just wondering what little scripts/programs people here have written that helps one with his
Ok, so here's what I want to do, preferably with jQuery 1.4.2: Have one
I have a one-to-one relationship but hibernatetool complains when generating the schema. Here's an
Here's the deal. I have a big class hierarchy and I have this one
Here's one I have always wondered about... Please excuse my naivety, but - How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.