[R] (no subject)

John Logsdon j.logsdon at quantex-research.com
Tue Dec 27 11:43:44 CET 2005


Is Barbara asking a much more basic question that is really RTFM?  

Apart from the apply family of commands, the S language as implemented in
R includes a lot of looping:

m<-3
for (z in 0:m){
	if(z>0){
		cat("z non-zero\n")
	}else{
		cat("z is zero\n")
	}
}

gives:

z is zero
z non-zero
z non-zero
z non-zero

As Jacques points out, typing ?Control will give a good overview of the
flow control features available, starting with:

if(cond) expr
if(cond) cons.expr  else  alt.expr

for(var in seq) expr
while(cond) expr
repeat expr
break
next

Following the links at the bottom of that help page will reveal the
richness of R commands (it's easier if you use a browser for help).

I really suggest one of the excellent books on S/R such as MASS.  After
all, as many of these are written by R contributors, it is a way of making
some small financial acknowledgement...:-)

Best wishes and Happy New Year to all

John

John Logsdon                               "Try to make things as simple
Quantex Research Ltd, Manchester UK         as possible but not simpler"
j.logsdon at quantex-research.com              a.einstein at relativity.org
+44(0)161 445 4951/G:+44(0)7717758675       www.quantex-research.com


On Tue, 27 Dec 2005, Jacques VESLOT wrote:

> 
> ?Control
> 
> but there are alternative ways :
> sapply(), apply(), lapply()...
> ifelse()
> etc.
> 
> 
> Barbora Kocúrová a écrit :
> 
> >Hallo.
> >Could you please tell me if it is possible in R use something 
> >like for-cycle or conditions with if and then.
> >I would need to index z from 0 to m and repeat some operations on each of them.
> >Could you please write me how can I do this?
> >Thank you very much
> >Barbora Kocurova
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> >
> >  
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list