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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:55:28+00:00 2026-05-21T15:55:28+00:00

There must be some algorithm that will make this easier than what I’m doing…

  • 0

There must be some algorithm that will make this easier than what I’m doing…

What I have are two arrays, each with two columns. One column in both is a timestamp, and the other in both is a measurement.

What needs to happen is turn this into a single array of: timestamp, measurement1, measurement2

The problem is the timestamps often won’t match up exactly. One array might be missing a value completely for a time period, or the timestamps might be off by an insignificant amount (insignificant enough that it would be OK to assign both measurements to the same timestamp).

Is there some well-known way of doing this fuzzy merge operation? A simple public domain function??

  • 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-05-21T15:55:29+00:00Added an answer on May 21, 2026 at 3:55 pm

    Start by asking yourself these questions: Do the arrays have the same number of elements? How do you want to combine two items with the same timestamp? How do you want to combine two items with different timestamp?

    You will probably have to write the algorithm yourself. Something like this would be easy to implement:

    1. Start by sorting each of the arrays individually by the timestamp order.
    2. Declare two iterators at the beginning of each input array respectively, and an empty output array.
    3. Then, you check which of the arrays has the earliest timestamp. Call it EARLY, and the other LATE.
      • If EARLY is close to LATE (by less than some constant), you apply a merge operation and insert the result at the end of the output array. Increment both iterators and go back to 3.
      • Otherwise, EARLY is far from LATE. You need to handle a missing value in the LATE array, perhaps by repeating the previous value or interpolating it using some function. Decide to insert or not a value in the output array. You only increment the EARLY array iterator in this case and go back to 3.
    4. If you have reached the end of either one of the arrays, the rest of the other array is LATE. You may want to interpret this as missing values and also repeat or interpolate the measurements.
    5. Return the output array.

    ~

    OutputArray merge(InputArray& a, InputArray& b) {
        InputArray::iterator a_it = a.begin();
        InputArray::iterator b_it = b.begin();
        while(a_it != a.end() && b_it != b.end()) {
            InputArray::iterator& early = *a_it.timestamp < *b_it.timestamp ? a_it : b_it;
            InputArray::iterator& late = *a_it.timestamp < *b_it.timestamp ? b_it : a_it;
            if(*late.timestamp - *early.timestamp < TIMESTAMP_CLOSE_ENOUGH) {
                output.timestamp = (*late.timestamp + *early.timestamp) / 2; // mean value
                output.measure1 = *a_it.measure;
                output.measure2 = *b_it.measure;
                outputArray.push_back(output);
                a_it++; b_it++;
            }
            else {
                output.timestamp = *early.timestamp;
                output.measure1 = *a_it.timestamp < *b_it.timestamp ? *a_it.measure : outputArray.back.measure1; // previous value if missing
                output.measure2 = *a_it.timestamp < *b_it.timestamp ? outputArray.back.measure2 : *b_it.measure;
                outputArray.push_back(output);
                early++;
            }
        }
    
        InputArray::iterator& late = a_it != a.end() ? a_it : b_it;
        InputArray::iterator late_end = a_it != a.end() ? a.end() : b.end();
        while(late != late_end) {
                output.timestamp = *late.timestamp;
                output.measure1 = a_it != a.end() ? *a_it.measure : outputArray.back.measure1; // previous value if missing
                output.measure2 = a_it != a.end() ? outputArray.back.measure2 : *b_it.measure;
                outputArray.push_back(output);
                late++;
        }
        return outputArray;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feeling that there must be client-server synchronization patterns out there. But
There must be a generic way to transform some hierachical XML such as: <element1
There must be an easy way to do this, but somehow I can wrap
There must be an easy way to do this. I build a Flex app
I think there must be something subtle going on here that I don't know
I know websphere does it, so there must be something that lets apache figure
Yes, There's More Than One Way To Do It but there must be a
I'm sure this is a relatively simple question, and there must be a good
I assume there must be a system and language independent way to just stick
Obviously I can do and DateTime.Now.After - DateTime.Now.Before but there must be something more

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.