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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:56:03+00:00 2026-06-18T02:56:03+00:00

I have multiple frames, for the purpose suppose 2. Each frame comprises 2 columns

  • 0

I have multiple frames, for the purpose suppose 2.
Each frame comprises 2 columns – an index column, and a value column

sz<-5;
frame_1<-data.frame(index=sort(sample(1:10,sz,replace=F)),value=rpois(sz,50));
frame_2<-data.frame(index=sort(sample(1:10,sz,replace=F)),value=rpois(sz,50));

frame_1:

 index value
  1    49
  6    62
  7    58
  8    30
 10    50

frame_2:

index value
  4    60
  5    64
  6    48
  7    46
  9    57

The goal is to create a third frame, frame_3, whose indices will be the union of those in frame_1 and frame_2,

frame_3<-data.frame(index = sort(union(frame_1$index,frame_2$index)));

and which will comprise two additional columns, value_1 and value_2.

frame_3$value_1 will be filled out from frame_1$value, frame_3$value_2 will be filled out from frame_2$value;

These should be filled out like so:
frame_3:

index value_1 value_2
1      49       NA
4      49       60     # value_1 is filled through with previous value
5      49       64     # value_1 is filled through with previous value
6      62       48     
7      58       46   
8      30       46     # value_2 is filled through with previous value
9      30       57     # value_1 is filled through with previous value
10     50       57     # value_1 is filled through with previous value

i’m looking for an efficient solution, as im dealing with records in the hundreds of thousands

  • 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-18T02:56:04+00:00Added an answer on June 18, 2026 at 2:56 am

    This problem screams for data.table. You can use a loop to recursively construct columns one by one using x[y, roll=TRUE].

    require(data.table)
    dt1 <- data.table(frame_1)
    dt2 <- data.table(frame_2)
    setkey(dt1, index)
    setkey(dt2, index)
    dt3 <- data.table(index = sort(unique(c(dt1$index, dt2$index))))
    > dt1[dt2[dt3, roll=TRUE], roll=TRUE]
    
    #    index value value.1
    # 1:     1    49      NA
    # 2:     4    49      60
    # 3:     5    49      64
    # 4:     6    62      48
    # 5:     7    58      46
    # 6:     8    30      46
    # 7:     9    30      57
    # 8:    10    50      57
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a binary file, inside of which has multiple frames. Each frame starts
I have multiple integer columns in a data frame, all with NAs that I
I have a very simple problem. I have a data frame with multiple rows
I have a data frame consisting of results from multiple runs of an experiment,
I have a various data.frames with columns of the same length where I am
Is it possible to have multiple data frames to be stored into one data
I have a MFC GUI app that has multiple frames (sort of like Outlook'ish
I have movieClips that have 2 frames, each frame has 3 layers, layer for
I have an image sprite of sorts with multiple frames for 1 button. I'm
I have to use 2 data frames 2 million records and another 2 million

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.