[R] really dumb question | loop counters in

Evan Cooch cooch17 at verizon.net
Sat Sep 22 00:54:07 CEST 2007


Thanks, but  there is nothing in section 9.2.2 that mentions seq(x,y,z) 
or anything close in a for loop.  All it says is (basically):


There is also a for loop construction which has the form
 > for (name in expr_1) expr_2
where name is the loop variable. expr 1 is a vector expression, (often a 
sequence like 1:20), and
expr 2 is often a grouped expression with its sub-expressions written in 
terms of the dummy
name. expr 2 is repeatedly evaluated as name ranges through the values 
in the vector result of
expr 1.

Moreover, I would have assumed it would be in the language definition 
file (not that I could find - I did check), the reference manual (nada), 
and so forth. If someone can point to the precise page in one of the 
standard - distributed - bits of R documentation the specifically says 
'here is how you use a non-unity incremental counter in an iterative 
loop in R', with an example, I'll stand corrected.

Duncan Murdoch wrote:
> On 21/09/2007 4:20 PM, Evan Cooch wrote:
>> Paul Hiemstra wrote:
>>> Hi,
>>>
>>> This works:
>>>
>>> for(i in seq(1,100,5)) {
>>> print(i)
>>> }
>>>
>>> Very similar to the way python does this kind of loop.
>>>
>>
>> Indeed it is - thanks for the tip. I'm still puzzled why I can't find 
>> a single piece of the standard [R] language documentation that shows 
>> this. In contrast, every single other language I use (more than I 
>> care to admit), and documentation for same, feature this prominently 
>> when they talk about looping.
>
> It's in "9.2.2 Repetitive execution: for loops, repeat and while" of 
> the Introduction to R manual. That's a good manual to read if you're 
> looking for an introduction to R.
>
> Duncan Murdoch
>
>



More information about the R-help mailing list