Home I'm trying to write a for loop but one of the values won't update. R
Reply: 1

I'm trying to write a for loop but one of the values won't update. R

user4343563
1#
user4343563 Published in 2018-01-11 20:50:01Z

This question already has an answer here:

  • Why do R objects not print in a function or a “for” loop? 3 answers

I'm just trying to write a simple for loops so I can see how much the person would owe after each consecutive year. It ends up printing the statement with only the n value ever changed. The A stays the same as the first time.

for (n in 1:15){
  A <-  5000 * (1+ .115/100) ^n
  sprintf("%.2f owed after %.f years", A, n) 
 }

I have no clue what to do to fix it. Thanks

satan
2#
satan Reply to 2018-01-11 21:01:48Z

You're missing a print statement-

   for (n in 1:15){
   A <-  5000 * (1+ .115/100) ^n
   print(sprintf("%.2f owed after %.f years", A, n)) 
   }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309221 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO