Reputation: 65
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?
Upvotes: 0
Views: 24753
Reputation: 49830
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)
Upvotes: 3