title: How to use the sum function in a for loop in R?
body: <p><img src="https://i.stack.imgur.com/ziMMH.gif" alt="enter image description here"></p>
  
  <p>We want to calculate the value of an integral in linear plot.
  For a better understanding look at the photo. Let's say the overall area is 1. We want to find what the value in a certain part is. For instance we want to know how much % of the overall 100% lay within the 10th and 11th month if everything refers to months and A as maximum stands for 24.
  We can calculate a integral and then should be able to get the searched area by F(x) - F(x-1)
  I thoght about the following code:</p>
  
  <pre><code>a &lt;- 24
  tab &lt;-matrix(0,a,1)
  tab &lt;-cbind(seq(1,a),tab)
  tab&lt;-data.frame(tab)
  
  #initialization for first point
  tab[1,2] &lt;- (2*tab[1,1] / a - tab[1,1]^2 / a^2)
  
  #for loop for calculation of integral of each point - integral until to the area
  for(i in 2:nrow(tab))
  {tab[i,2] &lt;- (2*tab[i,1] / a - tab[i,1]^2/ a^2) - sum(tab[1,2]:tab[i-1,2])}
  #plotting
  plot(tab[,2], type="l")
  </code></pre>
  
  <p>If you see the plot - it's confusing. Any ideas how to handle this correct?</p>