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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:41:29+00:00 2026-06-04T05:41:29+00:00

Take this dataset… test <- data.frame( t1=c(2,3,5,6,7,10,10), t2=c(3,4,6,7,8,11,12), id=1:7 ) …which looks like this.

  • 0

Take this dataset…

test <- data.frame(
    t1=c(2,3,5,6,7,10,10),
    t2=c(3,4,6,7,8,11,12),
    id=1:7
)

…which looks like this.
To clarify, each row is a previously identified link of two cases that have to stay bound together.

  t1 t2 id
1  2  3  1
2  3  4  2
3  5  6  3
4  6  7  4
5  7  8  5
6 10 11  6
7 10 12  7

I am hoping to identify the continuous sequences based on t2 == t1 recursively so that the links are:

link1 -  2-3,3-4
link2 -  5-6,6-7,7-8
link3 -  10-11
link4 -  10-12

The end result i’m looking for is this:

  t1 t2 id matchid
1  2  3  1       1
2  3  4  2       1
3  5  6  3       2
4  6  7  4       2
5  7  8  5       2
6 10 11  6       3
7 10 12  7       4

I have experimented with match(test$t2,test$t1) to get the initial links but am now getting stuck on how to continue the linking process.
My thoughts keep falling back to using a loop and that sounds like a terrible way to go.

  • 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-04T05:41:31+00:00Added an answer on June 4, 2026 at 5:41 am

    Here is one way to do it:

    test$matchid <- c(1, 1 + cumsum(tail(test$t1, -1) != head(test$t2, -1)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset that looks a little like this: a <- data.frame(x=rep(c(1,2,3,5,7,10,15,20), 5),
I'm trying to take a dataset that looks like this: And transform the records
I'd like to replace all values in my relatively large R dataset which take
I'm trying to take 21 bytes of data which uniquely identifies a trade and
I´m using a simple area chart based on a simple Dataset like this: DateTime(sql.timestamp)
I've got a two-column dataset with about 30000 clusters and 10 factors like this:
I'm looking to take a dataset like below and generate some statistics off the
I have a dataset with FASTA formatted sequencing, basically like this: >pc284 ATCGCGACTCGAC >pc293
I got a linq query. I wanna take this query results to a dataset.
I have a dataset which contains more than 50k rows. I decided to take

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.