Re: [R] for loop step

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Tue, 20 May 2008 13:39:28 -0500

You are doing it in your bit about 1:10, which is shorthand for generating a sequence 1, 2, 3, ..., 9, 10. Use ?seq to do what you want.

for(i in seq(1, 10, by = 2))

    cat(i, "\n")

Best,
Erik

Nair, Murlidharan T wrote:
> How do I define the incremental step in a "for" loop?
>
> for (j in 1:10){
> cat(j, "\n")
> }
>
> In the above example, if I want to increment j by 2 where do I specify that?
>
> Thanks
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



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 Tue 20 May 2008 - 18:44:21 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 Tue 20 May 2008 - 19:30:39 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