[R] extremely simple "for loop" question

Chris Bergstresser chris at subtlety.com
Thu Apr 13 00:14:14 CEST 2006


On 4/12/06, Paul Roebuck <roebuck at mdanderson.org> wrote:
> > I want to do a for loop in which m takes on the values
> > 1, 5, 10, 15, 20.  What is the syntax for doing that?
> >
> > I had been doing a loop for m in 1:20, but I only want
> > those values above.
>
> ?seq

... which doesn't handle the 1 in that sequence very elegantly.  You can do this

for (m in c(1, seq(5, 20, 5)))

   for the general case, but for the specific circumstance I'd do

for (m in c(1, 5, 10, 15, 20))

-- Chris




More information about the R-help mailing list