[R] print value of variable to screen or alert box?
David Winsemius
dwinsemius at comcast.net
Sat May 2 16:33:23 CEST 2009
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
More information about the R-help
mailing list