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

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

user806
1#
user806 Published in April 26, 2018, 5:19 pm

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

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO