3

I have this line in my code to create dots for a dot-density map. The function I'm misusing is dotsInPolys in the maptools package. I get this error when I run it and I'm not sure what it means. Can anyone help?

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

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

The given error is:

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

Eugene Brown
  • 4,032
  • 6
  • 33
  • 47

1 Answers1

2

Somewhere in your dataframe there are some NA values and you get the error.

Look what happens here:

 NA > 0 #this returns NA
[1] NA

If I use it in an if statement:

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

I get the same error as you.

In your case some instance of x[i] is NA and the above error is returned. You need to figure out a way to remove/deal with the NA values in your data.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87