[R] Plotting the diff. between two curves

Gabor Grothendieck ggrothendieck at gmail.com
Sat Nov 26 01:04:26 CET 2005


Using the zoo package you can merge the curves together
and use na.approx to fill in the blanks.  Assuming that
the first column in each instance is the x variable:

library(zoo)
Az <- zoo(A[,2], A[,1])
Bz <- zoo(B[,2], B[,1])
Cz <- na.approx(merge(Az, Bz))
plot(Cz[,1] - Cz[,2])


On 11/25/05, Prasanna <prasannaprakash at gmail.com> wrote:
> Dear Rs
>
> I have two vectors A and B
> where
>
> A is
>
>
>            V1        d
> 1  0.000100000 1.123278
> 2  0.002186431 1.120448
> 3  0.004351214 1.106661
> 4  0.006515998 1.107713
> 5  0.008680781 1.107667
> 6  0.013010348 1.106353
> 7  0.019504698 1.104077
> 8  0.034658181 1.103202
> 9  0.051976447 1.103200
> 10 0.073624280 1.094825
> 11 0.093085682 1.085123
> 12 0.095250465 1.087325
> 13 0.132051782 1.086158
> 14 0.168853098 1.084814
> 15 0.233774949 1.077453
> 16 0.296553665 1.076972
> 17 0.298718448 1.077258
> 18 0.354981166 1.073860
> 19 0.383123349 1.068163
> 20 0.398276832 1.068830
> 21 0.415595099 1.068267
> 22 0.426419015 1.066104
> 23 0.478373815 1.064580
> 24 0.534636533 1.062743
> 25 0.694808850 1.060799
> 26 0.816015067 1.037726
> 27 0.818179850 1.038340
> 28 0.820344634 1.027501
> 29 0.826838983 1.022188
> 30 0.829003767 1.017346
> 31 0.839827683 1.016244
> 32 0.841992467 1.007883
> 33 0.846322033 1.007745
> 34 0.852816383 1.006360
> 35 1.000000000 1.000000
>
> and  B is
>
>           V1        d
> 1 0.000100000 1.123278
> 2 0.002186431 1.112518
> 3 0.004351214 1.104332
> 4 0.006515998 1.091071
> 5 0.008680781 1.003591
> 6 0.010845564 0.948444
> 7 1.000000000 0.948444
>
>
> If I plot A and B, I will get two curves. However, is there any method to
> find the signed difference between these two curves so that I will have only
> one curve which shows the difference between these two curves?
>
> Thanks
> Prasanna
>
>
>
>
>
> --
> Prasanna BALAPRAKASH
> IRIDIA, Université Libre de Bruxelles
> 50, Av. F. Roosevelt, CP 194/6
> 1050  Brussels
> Belgium.
> http://iridia.ulb.ac.be/~prasanna
>
>        [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>




More information about the R-help mailing list