[R] displaying computation outputs inside "for" loops
Dewez Thomas
t.dewez at brgm.fr
Mon Aug 9 11:15:58 CEST 2004
Dear R-users,
I am puzzled by for loops and am kind of ashamed to ask because it is so
simple. There must be something I am missing in the way they are executed.
Basically, I would like to iterate a given number of time and generate a
bunch of stats (that's what loops are designed for, right?). Before doing
this I simply want to test simple procedure and see if they work (ie got the
syntax right - my main problem as I am new to R - and produce expected
results).
Even for something as basic as
for (i in 1:3) {i}
I get no screen output. Shouldn't R systematically display i for every loop
just like I am requesting with invoking "i"? When checking at the end of the
looping, i is indeed assigned to 5 but I cannot get intermediate values.
Further testing shows that i takes all the values in turn.
> for (i in 1:3) {str(i)}
int 1
int 2
int 3
but summary(i) doesn't display anything. Isn't there something weird with
this? Am I expecting something wrong and for loops just don't work that way,
unless using str() command? I tried print() and other descriptive commands
but to no avail.
A quick explanation would be grately appreciated
Thomas
***
Le contenu de cet e-mail et de ses pièces jointes est destin...{{dropped}}
More information about the R-help
mailing list