


Hello, Petr
Thanks for answering, 
I am trying to run a model,
 , so the data it just the values especify, This is what I was triyng to
 do, but it is comming the this error mesage, which I don't understand 
why becouse, I think that the sintacsi was fine, I couldn't fine any 
mistakes.


results <- data.frame (relativenes = NA, dispersal = NA, N= NA, N2=NA)
attach(results)
time = 100
K <- 100
nzero<- 10
r<-0.2
cost<- 0.5
      N[1] <- nzero
            for(i in 2: time){
            N[i]<-  N[i-1]*exp(r*(1 - N[i-1]/K))
            N[i] <- N[i]- (N[i]*dispersal[i])
            }
      N2[1] <- 0
            for(i in 2: time){
            N2[i]<-  N2[i-1]*exp(r*(1 - N2[i-1]/K))
            N2[i] <- N2[i]+ (N[i-1]*dispersal[i-1])
            }
      relativenes[1] <- 1/(2 * N[1] -((N[1]- 1)/2))
            for(i in 2: time){
            relativenes[i] <- 1/(2 * N[i] -((N[i]- 1)/2))
            }   
       
 dispersal[1] <-  if (relativenes[1] < cost) {dispersal[1] <- 
((relativenes[1]- cost)/(relativenes[1]- cost*cost))} else 
{dispersal[1]<- 0}
            for (i in 2: time){
            
dispersal[i] <- if (relativenes[i] < cost) {dispersal[i] 
<-((relativenes[i]- cost)/(relativenes[i]- cost*cost))} else 
{dispersal[i] <- 0}}
           
                 }
                     }







> Subject: Re: [R] If function error:  missing value where TRUE/FALSE needed
> From: petr.pikal@precheza.cz
> Date: Mon, 5 Mar 2012 08:33:15 +0100
> 
> Hi
> 
> It is strange. I get completely different error.
> 
> > dispersal[1] <-  if (any (relativenes[1] < cost)) ((relativenes[1]- 
> cost)/(relativenes[1]- cost*cost)) else 0
> Error: object 'relativenes' not found
> > for (i in 2: time){dispersal[i] <-  if (any (relativenes[i] < cost)) 
> ((relativenes[i]- cost)/(relativenes[i]- cost*cost)) else 0   }
> Error in 2:time : NA/NaN argument
> 
> It is probably due to fact that I do not have relativness or cost 
> variables available in my R version.
> 
> I can only guess that some relativnes values are NA and the comparison 
> results in NA which is treated by if as an inappropriate input so there is 
> missing value error. 
> 
> But without data and its structure it is only a guess.
> 
> Regards
> Petr
> 
> 
> > 
> > [R] If function error:  missing value where TRUE/FALSE needed
> > 
> > 
> > Hello!
> > I am trying to get a logic estatement in R using the if function, but it 
> 
> > is all the time comming and error, I have tryied different methods but 
> > nothing is working
> > the sentence is the following:
> > 
> > dispersal[1] <-  if (any (relativenes[1] < cost)) ((relativenes[1]- 
> cost)/
> > (relativenes[1]- cost*cost)) else 0
> >             for (i in 2: time){
> >             dispersal[i] <-  if (any (relativenes[i] < cost)) 
> > ((relativenes[i]- cost)/(relativenes[i]- cost*cost)) else 0   }
> > 
> > 
> >  dispersal[1] <-  if (relativenes[1] < cost) dispersal[1] <- 
> ((relativenes
> > [1]- cost)/(relativenes[1]- cost*cost)) else dispersal[1]<- 0
> >             for (i in 2: time){
> >             dispersal[i] <-  if  (relativenes[i] < cost)) dispersal[i] 
> <-
> > ((relativenes[i]- cost)/(relativenes[i]- cost*cost)) else dispersal[i] 
> <- 0   }
> > 
> > dispersal[1] <-  if (relativenes[1] < cost)  {dispersal[1] <- 
> > ((relativenes[1]- cost)/(relativenes[1]- cost*cost))} else 
> {dispersal[1]<- 0}
> >             for (i in 2: time){
> >             dispersal[i] <- if (relativenes[i] < cost) {dispersal[i] <-
> > ((relativenes[i]- cost)/(relativenes[i]- cost*cost))} else {dispersal[i] 
> <- 0}}
> > 
> >  Thanks Charo
> > 
> > 
> > 
> > 
> >    [[alternative HTML version deleted]]
> > 
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
 		 	   		  
	[[alternative HTML version deleted]]

