On May 2, 2009, at 7:59 AM, onyourmark wrote:


I am trying to debug a loop. Is there a way to print the value of a variable that is inside a loop? I have a vector v and inside a loop I have v[i] where i is the index of the loop. Is there a way to see v[i] per loop so that I
can see what is going on?
Thanks
--

> v <- vector()

> for (i in 1:5) { v[i] <- i^2; print(v[i])}
[1] 1
[1] 4
[1] 9
[1] 16
[1] 25

> for (i in 1:5) { v[i] <- i^2; print(paste(i, " squared = ", v[i]))}
[1] "1  squared =  1"
[1] "2  squared =  4"
[1] "3  squared =  9"
[1] "4  squared =  16"
[1] "5  squared =  25"

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to