> i <- 0
> while(i < 5) {
"do stuff"
print(i)
i <- i + 1
}
[1] 0
[1] 1
[1] 2
[1] 3
[1] 4
> i <- 0
> while(i < 5) {
"do stuff"
cat(i, "")
i <- i + 1
}
0 1 2 3 4 > i <- 0
> while(i < 100) {
"do stuff"
if((i %% 10) == 0)
cat(i, "")
i <- i + 1
}
0 10 20 30 40 50 60 70 80 90This was produced in S-Plus 6.2 under Windows 2000. For some reason, when I copy this code from S-Plus to R1.8.1 via XEmacs, this is locking up R for me right now, and I can't figure out why. However, I see no reason why these constructs would not work in R.
hope this helps. spencer graves
Marcos Sanches wrote:
Sorry, I forgot to correct the message subject, so I am resending my doubt it below:
Hi all!
I wrote a very basic program in R, which has some loops ('for' and 'while'). Is there a way to print the 'for' (or while) indice while the program is running so that I am able to estimate where the program is and how long it will last?
I mean, I want something like this:
i<-0 While(i<100){ "do a lot of commands" "print i" i<-i+1 }
How do I "print" the "i" at each step?
Thanks in advance,
Marcos
______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
