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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:41:17+00:00 2026-06-03T17:41:17+00:00

I have two data frames that look like something like the following: df1 <-

  • 0

I have two data frames that look like something like the following:

df1 <- data.frame(time=seq(0.0, by = 0.003, length.out = 1000))

   time
1 0.000
2 0.003
3 0.006
4 0.009
5 0.012
6 0.015
...

df2 <- data.frame(onset=c(0.0, 0.8, 1.9, 2.4), offset=c(0.799, 1.899, 2.399, 3.0))

  onset offset   A   B
1   0.0  0.799 ... ...
2   0.8  1.899 ... ...
3   1.9  2.399 ... ...
4   2.4  3.000 ... ...

In reality there are more columns in each of the data frames, and there are many more times in the first data frame and they’re not regularly spaced; there aren’t too many more rows in the second data frame. I want to merge the two data frames such that each row in the first data frame gets the extra columns for the appropriate range from the second data frame, and I want to do it efficiently because there are hundreds of thousands of rows involved.

  • 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-03T17:41:24+00:00Added an answer on June 3, 2026 at 5:41 pm

    You can use findInterval to match a time with the corresponding onset, then merge your two data.frames:

    df1$onset <- df2$onset[findInterval(df1$time, df2$onset)]
    df3 <- merge(df1, df2, by = "onset")
    
    head(df3)
    #   onset  time offset
    # 1     0 0.000  0.799
    # 2     0 0.003  0.799
    # 3     0 0.006  0.799
    # 4     0 0.009  0.799
    # 5     0 0.012  0.799
    # 6     0 0.015  0.799
    
    tail(df3)
    #      onset  time offset
    # 995    2.4 2.982      3
    # 996    2.4 2.985      3
    # 997    2.4 2.988      3
    # 998    2.4 2.991      3
    # 999    2.4 2.994      3
    # 1000   2.4 2.997      3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two data.frames. For examples sake let's say they look like this: df1
I have a data frame that looks like this, with two key columns and
I have a data frame that has a format like the following: Month Frequency
Is it possible to row bind two data frames that don't have the same
I have the following matching problem: I have two data.frames, one with an observation
I have two data frames, Data1 and Data2, that I want to merge based
Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep(Toaster, 3), rep(Radio,
I have two dataframes, much like these: data = data.frame(data=cbind(1:12,rep(c(1,2),6),rep(c(1,2,3),4))) colnames(data)=c('v','h','c') lookup = data.frame(data=cbind(c(rep(1,3),rep(2,3)),rep(c(1,2,3),2),21:26))
I have two data frames DF1, DF2 each with 2 vectors DF1$A DF1$B, DF2$C,
I have two data frames like so: A B 1 6 2 7 5

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.