[R] for loop step

Erik Iverson iverson at biostat.wisc.edu
Tue May 20 20:39:28 CEST 2008


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.



More information about the R-help mailing list