Skip to content
Prev 83238 / 398506 Next

(no subject)

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: