[R] extremely simple "for loop" question

David Scott d.scott at auckland.ac.nz
Thu Apr 13 01:11:23 CEST 2006

On Wed, 12 Apr 2006, Brian Quinif wrote:

> I am sorry to ask such a simple question, but my knowledge of
> programming language is extremely limited, and I couldn't find the
> answer in any of the normal resources.
> 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.
> Thanks,
> Brian

An easy one that doesn't need an answer from Gabor

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


for (m in c(1,5*(1:4))){

David Scott

David Scott	Department of Statistics, Tamaki Campus
 		The University of Auckland, PB 92019
 		Auckland	NEW ZEALAND
Phone: +64 9 373 7599 ext 86830		Fax: +64 9 373 7000
Email:	d.scott at auckland.ac.nz

Graduate Officer, Department of Statistics

ASC/NZSA 2006: "Statistical Connections"
The joint conference of the Statistical Society of Australia Inc.
and the New Zealand Statistical Association, July 3--6, 2006
in Auckland. Go to:


More information about the R-help mailing list