# Re: [R] if statement error

From: Lucke, Joseph F <Joseph.F.Lucke_at_uth.tmc.edu>
Date: Tue 17 Oct 2006 - 18:17:07 GMT

Jenny

This following example works:
> real.d <- rep(NA,30)
> real.b <- rep(NA,30)
> b1=runif(1); b2=runif(1); t1=runif(1); t2=runif(1)
> if (length(real.d)>=30 && length(real.b)>=30 &&
b1*b2*t1*t2>0){bool=TRUE}
> bool

[1] TRUE But this one doesn't:
> real.d <- rep(NA,30)
> real.b <- rep(NA,30)
> b1=runif(1); b2=runif(1); t1=runif(1); t2=NA
> if (length(real.d)>=30 && length(real.b)>=30 &&
b1*b2*t1*t2>0){bool=TRUE}
Error in if (length(real.d) >= 30 && length(real.b) >= 30 && b1 * b2 * :

missing value where TRUE/FALSE needed
>

NA's in the vector make no difference. && is correct. So, it appears at least one of your scalars is missing

Hi List,

Jen

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

[[alternative HTML version deleted]]

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 and provide commented, minimal, self-contained, reproducible code.

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 and provide commented, minimal, self-contained, reproducible code. Received on Wed Oct 18 04:30:30 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 17 Oct 2006 - 19:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.