title: Speed up the loop operation in R
body: <p>I have a big performance problem in R. I wrote a function that iterates over a <code>data.frame</code> object. It simply adds a new column to a <code>data.frame</code> and accumulates something. (simple operation). The <code>data.frame</code> has roughly 850K rows. My PC is still working (about 10h now) and I have no idea about the runtime.</p>
  
  <pre><code>dayloop2 &lt;- function(temp){
      for (i in 1:nrow(temp)){    
          temp[i,10] &lt;- i
          if (i &gt; 1) {             
              if ((temp[i,6] == temp[i-1,6]) &amp; (temp[i,3] == temp[i-1,3])) { 
                  temp[i,10] &lt;- temp[i,9] + temp[i-1,10]                    
              } else {
                  temp[i,10] &lt;- temp[i,9]                                    
              }
          } else {
              temp[i,10] &lt;- temp[i,9]
          }
      }
      names(temp)[names(temp) == "V10"] &lt;- "Kumm."
      return(temp)
  }
  </code></pre>
  
  <p>Any ideas how to speed up this operation?</p>