[R] for loops?

Pedro Rodrigues prodrigues at dcc.fc.up.pt
Mon Feb 2 16:08:26 CET 2004

On Mon, 2004-02-02 at 13:42, Catherine Stein wrote:
> Hello R people!
> How can one use a for loop (or something similar) in R?  As I type in each
> line, I get syntax errors... I'm just confused how much to type in at each
> ">" prompt.
> Thanks for your help,
> cathy


I believe you want something like:

for(i in 1:n){
...some lines here...

If you have only one line within the for loop you can use it without the

If the environment is still open (as within the for loop) you will not
get a new ">" prompt but a "+" prompt to continue as if you were writing
on the same line.

Only when you close the brackets the prompt will return to ">" after
executing the for loop.

Hope this will help.


   Pedro Pereira Rodrigues

   Phone: +351 226078830 - Ext: 121
   Snail: Department of Computer Science
	  Faculty of Sciences - University of Porto
	  Rua do Campo Alegre, 823
	  4150-180 Porto - Portugal

More information about the R-help mailing list