title: Index out of bounds error when using Rcpp function with mapply
body: <p>I get <code>"Error: index out of bounds"</code> when I am using <code>mapply</code> with a Rcpp function:</p>
  
  <p>R:</p>
  
  <pre class="lang-r prettyprint-override"><code>mapply(fun, x = totPrimas, y = factorProjec, w = totCurvadf)
  </code></pre>
  
  <p><code>x</code>, <code>y</code> and <code>z</code> are data frames with the same dimensions. </p>
  
  <p>Rcpp:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;Rcpp.h&gt;
  using namespace Rcpp;
  
  // [[Rcpp::export]]
  NumericVector fun(const NumericVector x, const NumericVector y, const NumericVector w ) {
    NumericVector z(x.size()); 
    z(0) = x(0) * y(0);
    NumericVector c(x.size()); 
    c(0) = x(0) * w(0);
    for(int i = 1; i &lt; x.size(); i++) {
      c(i) = (c(i-1) + x(i)) * w(i); 
      z(i) = c(i) * y(i);
    }
    return z;
  }
  </code></pre>
  
  <p>Is something wrong in the code? Thanks alot.</p>