Re: [R] incrementing for loop by 2

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Thu, 24 Jul 2008 09:07:45 -0500

on 07/24/2008 07:59 AM Clark, Jennifer H wrote:
> Dear List-serv members: How can I structure a for loop so that it
> will increment the counter by two using R? I am just looking for a
> simple example that shows where the incrementing part should go.
> Thanks!

It would be helpful to have an idea of what you are trying to accomplish, as there may very well be a better way than using a 'for' loop.

That being said:

 > for (i in seq(0, 10, 2)) print(i)

[1] 0
[1] 2
[1] 4
[1] 6
[1] 8
[1] 10


See ?seq

HTH, Marc Schwartz



R-help_at_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. Received on Thu 24 Jul 2008 - 14:20:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jul 2008 - 14:32:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive