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 8939059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:16+00:00 2026-06-15T10:45:16+00:00

I’m working with a dataset that looks something like this, except there are many

  • 0

I’m working with a dataset that looks something like this, except there are many more columns with data like “serial” and “loc”:

start <-c(1,8,16,24,28,32)
end   <-c(4,9,20,27,30,45)
serial<-c(1,2,3,4,5,6)
loc<-c(8,63,90,32,89,75)
dataset<-data.frame(cbind(start,end, serial,loc))

Here each row actually represents a run of consecutive integers; I’d like to make each of those consecutive integers into its own row and conserve the other attributes of that row. “start” indicates the beginning of a run and “end” represents the end of the run. So, for example, in the first row in “dataset”, I would like to have that row separated into four rows: one for 1, one for 2, one for 3, and one for 4. Likewise, the second row in “dataset” would be split into two rows: one for 8 and one for 9 etc.

Thus the output for running just the first two lines of “dataset” would look like:

split serial loc
    1 1 8
    2 1 8
    3 1 8
    4 1 8
    8 2 63
    9 2 63
  • 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-06-15T10:45:17+00:00Added an answer on June 15, 2026 at 10:45 am

    Here’s one approach sticking with base R.

    temp <- mapply(seq, dataset$start, dataset$end)
    dataset2 <- data.frame(serial = rep(dataset$serial, sapply(temp, length)),
                           index = unlist(temp),
                           loc = rep(dataset$loc, sapply(temp, length)))
    list(head(dataset2), tail(dataset2))
    # [[1]]
    #   serial index loc
    # 1      1     1   8
    # 2      1     2   8
    # 3      1     3   8
    # 4      1     4   8
    # 5      2     8  63
    # 6      2     9  63
    # 
    # [[2]]
    #    serial index loc
    # 27      6    40  75
    # 28      6    41  75
    # 29      6    42  75
    # 30      6    43  75
    # 31      6    44  75
    # 32      6    45  75
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.