Skip to content
Prev 76070 / 398502 Next

(Fwd) Re: priority of operators in the FOR ( ) statement

Hi
On 23 Aug 2005 at 12:03, Ravi.Vishnu at outokumpu.com wrote:

            
program
Thomas
took
that R 

<snip>
*****************************************************
*****************
I also wonder if this function computes what is intended 

maybe this 

vec<-c(0,sqrt(2),sqrt(2)+1,sqrt(2)+1.5) 

myfun<-function(x,vec) { 

y<-x/2 
y0<-c(0,1,.2,.6,0)[findInterval(x,vec)+1] 
pos<-which(y0%in%1) 
y0[pos]<-y[pos] 
y0 
} 

vec<-c(0,sqrt(2),sqrt(2)+1,sqrt(2)+1.5)
[1] 1.62 0.05 1.67   NA   NA
will do it more efficiently. 

HTH 
Petr
*****************************************************
Petr Pikal
petr.pikal at precheza.cz