0

I'm trying to number different rain-events! each new event starts (gets a new number), if there was no rainfall for a certain period of time (time.steps.event.end). But somehow R gives me an Error-message. Funny is, that the same code works, with a shorter list of measurements (in the same format). To your information: R always gives me the Error at i=1577739 out of 1577809 measurements.

This is (the faulty part of) my code:

 i=1
 rain.index=0
 finedata=rain.series.matrix[,3]

 while(i<(length(finedata)-time.steps.event.end+1)) { 
   if (finedata[i]==0)
     i=i+1 else {

  rain.index=rain.index+1

  rain.series.matrix[(i-max(durations)/20):i,2]=rain.index


  while(any(finedata[(i+1):(i+time.steps.event.end)]>0)) 
  {
    i=i+1
    rain.series.matrix[i,2]=rain.index

  }
  rain.series.matrix[(i+1):(i+time.steps.event.end),2]=rain.index
  i=i+1
}
}

The following Error is showing:

Error in while (any(finedata[(i + 1):(i + time.steps.event.end)] > 0,  : 
  missing value where TRUE/FALSE needed

Can anybody help me?

1
  • 2
    Although I love the enthusiasm for numbering rain events, it's hard to give a specific answer because you have not provided enough data/code. Please see stackoverflow.com/questions/5963269/…
    – GSee
    Sep 29, 2013 at 13:38

1 Answer 1

3

The error is telling you that you are trying to compare two things, but one of them is missing.

Here is a more succinct, reproducible example

x <- 1:2
x[3:4]
#[1] NA NA
while(any(x[3:4] > 0)) print(TRUE)
#Error in while (any(x[3:4] > 0)) print(TRUE) : 
#  missing value where TRUE/FALSE needed

Maybe you could specifically check for NAs like this

while(!any(is.na(x[3:4])) && any(x[3:4] > 0)) print(TRUE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.