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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:14:08+00:00 2026-06-01T15:14:08+00:00

I have two data frames with two columns each. The first column is timestamps

  • 0

I have two data frames with two columns each. The first column is timestamps and the second contains some values.
One of the data frames is much bigger than the other one but both of them contains data in the same timestamp range.

If I plot these two on top of each other, I will get a nice plot showing how they differ in time.

Now I would like to get the absolute difference by time of these two dataframes to make a another plot showing how much they differ (or to create a boxplot with this information) even though they do not have the same length and exact matching timestamps.

Check this example:

df1:

timestamp | data
1334103075| 1.2
1334103085| 1.5
1334103095| 0.9
1334103105| 0.7
1334103115| 1.1
1334103125| 0.8

df2:

timestamp | data
1334103078| 1.2
1334103099| 1.5
1334103123| 0.8
1334103125| 0.9

How would I achieve something like this:

df3 <- abs(df1-df2)

As you see df2 might not have the same timestamps as df1, but they both have timestamps in the same time range.

Of course the subtraction should try to match timestamps or subtract values from timestamp averages that they are near.

  • 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-01T15:14:09+00:00Added an answer on June 1, 2026 at 3:14 pm

    I would suggest using two linear interpolators and evaluate both of them on the union of your two sets of timestamps:

    df1 <- data.frame(timestamp = c(1334103075, 1334103085, 1334103095,
                                    1334103105, 1334103115, 1334103125),
                      data      = c(1.2, 1.5, 0.9, 0.7, 1.1, 0.8))
    
    df2 <- data.frame(timestamp = c(1334103078, 1334103099, 1334103123,
                                    1334103125),
                      data      = c(1.2, 1.5, 0.8, 0.9))
    
    library(Hmisc)
    all.timestamps <- sort(unique(c(df1$timestamp, df2$timestamp)))
    data1 <- approxExtrap(df1$timestamp, df1$data, all.timestamps)$y
    data2 <- approxExtrap(df2$timestamp, df2$data, all.timestamps)$y
    
    df3 <- data.frame(timestamp = all.timestamps,
                      data1     = data1,
                      data2     = data2,
                      abs.diff  = abs(data1 - data2))
    df3
    #    timestamp data1    data2   abs.diff
    # 1 1334103075  1.20 1.157143 0.04285714
    # 2 1334103078  1.29 1.200000 0.09000000
    # 3 1334103085  1.50 1.300000 0.20000000
    # 4 1334103095  0.90 1.442857 0.54285714
    # 5 1334103099  0.82 1.500000 0.68000000
    # 6 1334103105  0.70 1.325000 0.62500000
    # 7 1334103115  1.10 1.033333 0.06666667
    # 8 1334103123  0.86 0.800000 0.06000000
    # 9 1334103125  0.80 0.900000 0.10000000
    

    Then you could consider fitting splines if you are not quite happy with linear approximations.

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

Sidebar

Related Questions

I have a data frame with two columns. First column contains categories such as
I have a list L of data frames with two columns each...a key, and
I have 2 data frames with different number of columns each. Some of the
I have two data.frames in R, one of which has two columns and of
I have two data.frames each with three columns: chrom, start & stop, let's call
I am using R and I have two data frames: carrots and cucumbers. Each
i have two data tables with the same structure the first one has one
Let's say I have two data frames. Each has a DAY, a MONTH, and
I have the following matching problem: I have two data.frames, one with an observation
I have a data.frame with 20 columns. The first two are factors, and 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.