I'm trying to see how to store all my info in one table so i can print it at the end of the loop, here is the code I'm using
trips = 1000
f1 = 0
f2 = 0
c1 = 18
c2= 12
#Incremental with proportional factors
factors = c(0,.35,0.25,0.20,.15,.05)
n = 6
for(i in 1:n)
{
if(c2 < c1)
{
increment = trips * factors[i]
f2 = f2 + increment
c2 = 12 + (.01*f2)
}
else
{
increment = trips * factors[i]
f1 = f1 + increment
c1 = 18 + (.005*f1)
}
IncrementalTable = c(i - 1,increment,f2,c2,f1,c1)
}
I'd like to store each iteration in the IncrementalTable variable, at the moment i only know how to store one iteration at the time. How do i store it as a table to preserve all the iterations?
something like this
Incremental Table = N I F2 C2 F1 C2
0 0 0 12 0 18
1 350 350 15.5 0 18.0
2 250 600 18 0 18
3 200 600 18 200 19
4 150 750 19.5 200 19
5 50 750 19.50 250 19.25
forloop. Is theforloop of critical importance?c1&c2at the top, so the first pass through the loop will be problematic. Also, note that you are wiping out your previous version ofIncrementalTableon each successive pass through the loop. Can you include what you want the output to look like, in addition?rbindto figure out how to record each row. However, try to pre-allocate your finaldata.frameand update rows in each iteration, rather than inserting new rows.