title: Why is the sum of the area under density curve always greater than 1 (R)?
body: <p>I found codes to calculate the sum of the area under a density curve in R. Unfortunately, I don't understand why there is always an extra ~"0.000976" at the area... </p>
  
  <pre><code>nb.data = 500000
  y = rnorm(nb.data,10,2)
  
  de = density(y)
  
  require(zoo)
  sum(diff(de$x[order(de$x)])*rollmean(de$y[order(de$x)],2))
  
  [1] 1.000976
  </code></pre>
  
  <p>Why is that so? </p>
  
  <p>It should be equal to 1, right?</p>