Re: [R] (no subject)

From: John Logsdon <j.logsdon_at_quantex-research.com>
Date: Tue 27 Dec 2005 - 21:43:44 EST


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@quantex-research.com              a.einstein@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@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@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@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 Received on Tue Dec 27 21:52:17 2005

This archive was generated by hypermail 2.1.8 : Tue 27 Dec 2005 - 23:54:11 EST