Reputation: 11
This is a super basic question but I always struggle to get loops to run in R and output correctly. I have an initial value of 180000 and I want to apply a loop that calculates a growth over 50 years of 0.5% each year. I hope to create a vector or from this so I can index it later. Thanks for any help!
Upvotes: 0
Views: 34
Reputation: 101327
If you want a vector, then here it is
v <- 18000*(1+0.005)**(0:49)
Upvotes: 2
Reputation: 533
Maybe I'm misunderstanding your question because you don't mention a language but here is a java example:
int a = 180000;
for(int year=0; year<50; year++) {
a *= 1.005; // add 0.5% each year
}
Not sure what you mean with the vector part.
Upvotes: -1