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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:40:35+00:00 2026-06-13T22:40:35+00:00

I have two different datasets ( c1 and c2 ), which are plotted together

  • 0

I have two different datasets (c1 and c2), which are plotted together in one graph. both curves have different x- and y-values:

c1 = data.frame(
  x=c(0,1.1,2,  3,  4,  5),
  y=c(0,1.1,1.9,3.2,4.3,5.2)
)
c2 = data.frame(
  x=c(0,0.3,0.9,2.1,3.2,4.2,5),
  y=c(0,0.4,1.5,2.3,3.2,4.1,5.1)
)
plot(c1, type="o", col=2)
lines(c2, type="o", col=3)

Now I like to plot the residuals of the two curves (res=c1-c2) for all unique x values (unique(c(c1$x, c2$x))). This would be easy if I had the same x-values. But it seems, that I have to interpolate all missing x-values and add them to the measured dataset.

Is there an easy way for doing this in R?

  • 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-13T22:40:38+00:00Added an answer on June 13, 2026 at 10:40 pm

    How about this:

    On the values c1$x:

    c1$y - approx(c2$x, c2$y, c1$x)$y
    # [1]  0.0000000 -0.5333333 -0.3333333  0.1636364  0.3800000  0.1000000
    

    on the values c2$x:

    approx(c1$x, c1$y, c2$x)$y - c2$y
    # [1]  0.00 -0.10 -0.60 -0.27  0.22  0.38  0.10
    

    Or, putting it all together,

    x <- sort(unique(c(c1$x, c2$x)))
    approx(c1$x, c1$y, x)$y - approx(c2$x, c2$y, x)$y
    # [1] 0.0000000 -0.1000000 -0.6000000 -0.5333333 -0.3333333 -0.2700000  0.1636364  0.2200000
    # [9] 0.3800000  0.3800000  0.1000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two datasets each with one data table pulled from different sources and
I have two different tables from which I need to pull data blogs which
I have a UIPickerView which will be loaded with two different data sets based
I have two different libGL libraries on the same Ubuntu 11.04 machine. One library
I have two different buttons on my page. I want them both to be
I have two different arrays, one with strings and another with ints. I want
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
I have two different modules that need access to a single file (One will
I need some help with data analysis. I do have two datasets (before &
I have two datasets returning to two different backbone collections each using a different

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.