[R] if statement error

Dieter Menne dieter.menne at menne-biomed.de
Tue Oct 17 19:38:04 CEST 2006


Jenny Stadt <jennystadt <at> yahoo.ca> writes:

> if(length(real.d)>=30 && length(real.b)>=30 && 
   beta1*beta2*theta1*theta2>0 )
> 
> { r <- 1;  corr <- 1;  }
> 
> real.d and real.b are two vectors, beta1,beta2,theta1,and theta2 are
> constants. The error occurred like this:
> 
> Error in 
> if (length(real.d) >= 30 && length(real.b) >= 30 && beta1 * beta2 *  : 
>         missing value where TRUE/FALSE needed

Please follow the advice and provide a full example, where beta1 really is
a vector. This works for me below, but it give the message you mentioned if 
you uncomment second line.

Dieter

-------------
beta1 = beta2 =  theta1 = theta2 = 1.0
#beta1 = NULL
real.d = runif(35)
real.b = runif(35)
r=corr=0
if(
  length(real.d)>=30 && 
  length(real.b)>=30 && 
  beta1*beta2*theta1*theta2>0 ) { 
  r <- 1;  
  corr <- 1;  
}



More information about the R-help mailing list