title: How to obtain the cumulative distribution function
body: <p>I have a random variable which I can obtain the density of </p>
  
  <pre><code>density(r)-&gt;pdf
  </code></pre>
  
  <p>how can I obtain the cumulative distribution function (cdf) from this pdf with R?</p>
  
  <p>I tried </p>
  
  <pre><code>approxfun(pdf$x,pdf$y,yleft=0,yright=0)-&gt;f
  cdf&lt;-integrate(f,-Inf,2)
  </code></pre>
  
  <p>but when I plot cdf I only obtain </p>
  
  <p>1.000396 with absolute error &lt; 7.9e-05</p>