[R] Help with error in "if then" statement

From: Andrew Rominger <rominger_at_stanford.edu>
Date: Fri, 11 Jul 2008 09:48:05 -0700

Dear list,

I'm afraid this is a mundane question. Here's the background: I've produced a function which allows me to sequentially measure angles and distances from a specified reference point to a curve defined by empirical data points while (i.e. using a while loop) the angle being measured is within certain bounds. Because the curve is circular I need to pars the data into basically an "upper" curve and "lower" curve. I tried to do this with an if statement, specifically:

ycrit<-subset(data,subset=data$x==min(data$x) y.max<-length*sin(angle)+y.ref #length, angle and y.ref are given if(y.max<ycrit){

Now the problem: The while loop works for 4 iterations, until I get the error message:

"Error in if (y.max < ycrit) { : missing value where TRUE/FALSE needed"

When I forced the function to print y.max and ycrit for each iteration of the while loop, it returns finite real numbers, including ycrit = 153.5 and y.max = 245.16 for the step which returns the error message.

Any ideas about what's going on here--why does R "think" that 245.16<153.5 is "missing," or is anything other than TRUE/FALSE? Am I using "if" incorrectly? In which case would it be more appropriate to perhaps create subsets of the data points based on < or > ycrit?

Thanks in advance for any guidance--

Andrew J. Rominger
Department of Biological Sciences
Stanford University

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 11 Jul 2008 - 17:37:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Jul 2008 - 16:31:31 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.

list of date sections of archive