2014-12-24 35 views
3

我的代碼中有這一行爲點密度映射創建點。我誤用的函數是mantools包中的dotsInPolys。我運行它時出現此錯誤,但我不確定它的含義。誰能幫忙?if(x [i]> 0)中的錯誤{:缺少值,其中TRUE/FALSE需要

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

新南威爾士州是一個shape文件和datajoin $ pop.10是數字向量。

給定的錯誤是:

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

回答

2

某處在你的數據幀有一些NA值,你會得到錯誤。

這裏看看會發生什麼:

NA > 0 #this returns NA 
[1] NA 

如果我在if語句中使用它:

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

我得到同樣的錯誤,你。

在你的情況下,x[i]的某個實例是NA並返回上述錯誤。您需要找出一種方法來刪除/處理數據中的NA值。

相關問題