Reputation: 49
N <- c(6, 11, 21)
for (t in 4:20) {
N[t] <- round( 0.5*N[t-1] + sqrt(N[t-2]) + log10(1+N[t-3]) )
}
N
## [1] 20
I'm trying to print out the contents of N each time it runs in RStudio but am running into the issue of it only printing out one number (20 in this instance) instead of the the entire range of numbers. There seems to be a very simple way to fix this, but as I am very new to R and programming I'm stumped.
Upvotes: 0
Views: 51
Reputation: 26
so i think that you maybe are just trying to print N out, and not t
N <- c(6, 11, 21)
for (t in 4:20) {N[t] <- round( 0.5*N[t-1] + sqrt(N[t-2]) + log10(1+N[t-3]) )}
N
[1] 6 11 21 15 13 12 11 10 9 9 9 8 8 8 8 8 8 8 8 8
Upvotes: 1