Error in R: Having output to be equal to zero : <p>I'm having some issue concerning the following code.  I should get the value of v1 = ( 106.56, 247.97, 417.00, 505.70) but i'm getting it to be ( 106.56, 247.97, 417.00, 0). I can't figure out what the problem is. Can someone please help me out? Thank you in advance. </p>

<pre><code>a &lt;- 0.0008; 
b &lt;- 0.00011; 
c &lt;- 1.095; 
m &lt;- b/log(c, base=exp(1)); 
z &lt;- (-a/log(c, base=exp(1)))+1;
e &lt;- exp(1);

x &lt;- 30;
k &lt;- 0:69;
del &lt;- 0.05;
v &lt;- e^(-del);
j &lt;- m*c^x;
j1 &lt;- m*c^(x+k);
p &lt;- e^(-a*k+j-j*c^k);
q1 &lt;- e^j1*gamma(z)*(j1^(1-z))*(pgamma(c, z, j1)-pgamma(1, z, j1)); 
q2 &lt;- 1-e^(-a-j1*c+j1)-q1; 
p1 &lt;- p*q1;
p2 &lt;- p*q2;
p3 &lt;- p1+p2;
apbw &lt;- sum(p3*v^(k+1)); 
app &lt;- e^j*sum(v^k*e^(-a*k-j*c^k)); 
pw &lt;- 1000*apbw/app; 
apb &lt;- cumsum(p2*v^(k+1));
apbn &lt;- apb [35]; 
app &lt;- e^j*cumsum(v^k*e^(-a*k-j*c^k));
appn &lt;- app[35];
pn &lt;- 1000*apbn/appn;

k &lt;- vector('list', 4);
p &lt;- vector('list',4);
q &lt;- vector('list',4);
j1 &lt;- vector('list',4);
q1 &lt;- vector('list',4);
p1 &lt;- vector('list',4);
p2 &lt;- vector('list',4);
p3 &lt;- vector('list',4);
w &lt;- vector('list',4);
wa &lt;- vector('list',4);
t1 &lt;- vector('list',4);
t2 &lt;- vector('list',4);
ta &lt;- vector('list',4);
nta &lt;- vector('list',4);
vb &lt;- vector('list',4);
vt &lt;- vector('list',4);
v1 &lt;- vector('list',4);
d &lt;- vector('list',4);

t &lt;- c(10, 20, 30, 35);
x1 &lt;- x + t;

for(i in 1:4)
{
j[[i]] &lt;- m*c^x1[i];
k[[i]] &lt;- 0:(100 - x1[i] - 1);
j1[[i]] &lt;- m*c^(x1[i]+k[[i]]);
p[[i]] &lt;- e^(-a*k[[i]]+j[[i]]-j[[i]]*c^k[[i]]); 
q[[i]] &lt;- e^j1[[i]]*gamma(z)*(j1[[i]]^(1-z))*(pgamma(c, z, j1[[i]])-  pgamma(1,  z, j1[[i]]));
q1[[i]] &lt;- 1-e^(-a-j1[[i]]*c+j1[[i]])-q[[i]];
p1[[i]] &lt;- p[[i]]*q[[i]];
p2[[i]] &lt;- p[[i]]*q1[[i]];
p3[[i]] &lt;- p1[[i]]+p2[[i]];
w[[i]] &lt;- sum(p3[[i]]*v^(k[[i]]+1)) ;
wa[[i]] &lt;- e^j[[i]]*sum(v^k[[i]]*e^(-a*k[[i]]-j[[i]]*c^k[[i]]));
t1[[i]] &lt;- cumsum(p2[[i]]*v^(k[[i]]+1));
t2[[i]] &lt;- t1[[i]][65-x1[i]] ;
ta[[i]] &lt;- e^j[[i]]*cumsum(v^k[[i]]*e^(-a*k[[i]]-j[[i]]*c^k[[i]]));
nta[[i]] &lt;- ta[[i]][65-x1[i]];
vb[[i]] &lt;- round(1000*w[[i]]-(pw*wa[[i]]), 2);
vt[[i]] &lt;- round(1000*t2[[i]]-(pn*nta[[i]]), 2);
v1[[i]] &lt;- vb[[i]]+vt[[i]];  
}  
</code></pre>
