Error in if (x [i]> 0) {: missing value requiring TRUE / FALSE

I have this line in my code to generate points for a density point map. The function I'm using is dotsInPolys in the maptools package. I am getting this error when I run it and I am not sure what it means. Can anyone please help?

NSWdots <- dotsInPolys(NSW, as.integer(datajoin$pop.10))

NSW is a shapefile and datajoin $ pop.10 is a vector of numbers.

This error:

Error in if (x[i] > 0) { : missing value where TRUE/FALSE needed

+3


source to share


1 answer


There are multiple values ​​somewhere in your framework NA

and you will get an error.

See what's going on here:

 NA > 0 #this returns NA
[1] NA

      

If I use it in the instructions if

:



> if (NA > 0) print('Hello')
Error in if (NA > 0) print("Hello") : 
  missing value where TRUE/FALSE needed

      

I am getting the same error as you.

In your case, some instance x[i]

is equal NA

and the above error is returned. You need to figure out a way to remove / process values NA

in your data.

+2


source







All Articles