title: Calculating residuals of two curves with different datapoints in R
body: <p>I have two different datasets (<code>c1</code> and <code>c2</code>), which are plotted together in one graph. both curves have different x- and y-values:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Now I like to plot the residuals of the two curves (<code>res=c1-c2</code>) for all unique x values (<code>unique(c(c1$x, c2$x))</code>). 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.</p>
  
  <p>Is there an easy way for doing this in R?</p>