This question already has an answer here:
这个问题已经有了答案:
- Error in if/while (condition) {: missing Value where TRUE/FALSE needed 2 answers
- if/while(条件){:缺失值,TRUE/FALSE需要2个答案。
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?
我在我的代码中有这条线,为点密度图创建点。我在maptools包中误用的函数是dotsInPolys。当我运行它时,我得到这个错误,我不确定它的意思。谁能帮忙吗?
NSWdots <- dotsInPolys(NSW, as.integer(datajoin$pop.10))
NSWdots < - dotsInPolys(新南威尔士州as.integer(datajoin pop.10美元))
NSW is a shapefile and datajoin$pop.10 is a vector of numbers.
NSW是一个shapefile和datajoin$pop。10是一个数字的向量。
The given error is:
给定的误差:
Error in if (x[i] > 0) { : missing value where TRUE/FALSE needed
if (x[i] > 0){:缺少TRUE/FALSE需要的值。
1 个解决方案
#1
2
Somewhere in your dataframe there are some NA
values and you get the error.
在dataframe的某个地方有一些NA值,会得到错误。
Look what happens here:
看看发生了什么:
NA > 0 #this returns NA
[1] NA
If I use it in an if
statement:
如果我在If语句中使用它:
> 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.
在您的例子中,x[i]的某个实例是NA,并且返回上面的错误。您需要找到一种方法来删除/处理数据中的NA值。
#1
2
Somewhere in your dataframe there are some NA
values and you get the error.
在dataframe的某个地方有一些NA值,会得到错误。
Look what happens here:
看看发生了什么:
NA > 0 #this returns NA
[1] NA
If I use it in an if
statement:
如果我在If语句中使用它:
> 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.
在您的例子中,x[i]的某个实例是NA,并且返回上面的错误。您需要找到一种方法来删除/处理数据中的NA值。