I have data that looks like this. In which I want to plot accumulative value of dat1 with respect to x-axis. Also plot it together with dat2.
#x-axis dat1 dat2 -10 0.0140149 0.0140146 -9 0.00890835 0.00891768 -8 0.00672276 0.00672488 -7 0.00876399 0.00879401 -6 0.00806879 0.00808141 -5 0.0088366 0.00885121 -4 0.00856872 0.00857769 -3 0.0195384 0.0196094 -2 0.0160239 0.0161829 -1 0.0254455 0.0257845 0 0.0397413 0.0400913 1 0.0743316 0.0755453 2 0.0247501 0.0253324 3 0.0214285 0.021778 4 0.0241462 0.0244967 5 0.0150943 0.015241 6 0.0141398 0.0142373 7 0.0101515 0.0102948 8 0.0308843 0.031294 9 0.0095504 0.00960626 10 0.00729676 0.0073713
What’s the common way to do it in R?
I looked at ECDF from Hmisc, it doesn’t seem to do what I want. In particular it doesn’t allow us to give x-axis value.
I think the function you are looking for is
cumsum()which will do a cumulative sum on a vector.I use the function points above in order to add dat2 to the existing plot. Run this in R and see if it gives you what you need.