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.