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

  • Home
  • SEARCH
  • 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 9210515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:05:53+00:00 2026-06-18T01:05:53+00:00

This question is a follow-up to a previous question: Click In this question two

  • 0

This question is a follow-up to a previous question: Click

In this question two data.frames are provided, since this question focuses on a more specific part, the example data is reduced.

tc <- textConnection('
ID  Track4  Time    Loc
4   50      40      1   
5   55      50      1   
6   55      60      1   

')

MATCHINGS <- read.table(tc, header=TRUE)

tc <- textConnection('
ID  Track4  Time    Loc
""  50      40      1   
""  55      10      1
""  55      40      1   
""  55      59      1     ')  

INVOLVED <- read.table(tc, header=TRUE)

In the previous question a solution was found to this problem: The goal is to place the least recent ID from MATCHINGS into INVOLVED by matching on Track1 and Loc. An extra condition is that the Time of the matching INVOLVED entry may not be higher than the Time of the entry in MATCHING. This was achieved with the current approach (see below)

A new constraint is that: the Time of the INVOLVED entry may not be more than 30 seconds (Time column is in seconds) lower than the MATCHINGS entry. Right now the following output is achieved:

ID Track4 Time Loc
4     50   40   1
5     55   10   1
5     55   40   1
6     55   59   1

The expected results are however:

ID Track4 Time Loc
4     50   40   1
""    55   10   1
5     55   40   1
6     55   59   1

Since the Time of the INVOLVED entry is more than 30 seconds lower than the MATCHINGS entry that matches on Track4 and Loc. I do not see how to incorporate this in my current solution. According to Matthew Dowle a feature request in de data.table package is related to this issue, but it should already be possible to incoporate. Does anyone know how?

The current approach (Without taking the time constraint into account)

M = as.data.table(MATCHINGS)
I = as.data.table(INVOLVED)
M[,Time:=-Time]
I[,Time:=-Time]
setkey(M,Loc,Track4,Time)
I[,ID:={i=list(Loc,Track4,Time);M[i,ID,roll=TRUE,mult="first"]}][,Time:=-Time]  
  • 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-18T01:05:54+00:00Added an answer on June 18, 2026 at 1:05 am

    Update: roll argument in data.table accepts finite roll backs and roll forwards since A LONG TIME. Just updating this post so that we can close #615.

    # dt1 = MATCHES, dt2 = INVOLVED
    # make sure dt2 doesn't have `ID` column, or if it has, it is of integer type
    require(data.table) # v1.9.6+
    dt2[dt1, ID := i.ID, on=c("Track4", "Time"), roll=30]
    #    Track4 Time Loc ID
    # 1:     50   40   1  4
    # 2:     55   10   1 NA
    # 3:     55   40   1  5
    # 4:     55   59   1  6
    

    Also using the on= argument implemented in v1.9.6.

    See history for the older answer if necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a more specific question to follow up on [another question that I
As a follow up to this previous question , I have a Core Data-based
This question is a follow up with a previous question Previous Question The previous
This is a follow up question to a previous question I asked about calculating
This is a follow on from my previous question although this is about something
This is a follow-up question related to my previous post . Below is a
This is really a follow on question to a previous one , where I
This post if a follow-up question to mt previous post: Android RESTful Web application
This is a follow up from my previous question I have this code basically
This is a follow-up to my previous question . Suppose I am writing the

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.