2014-07-01 31 views
0

我有兩個柵格,我想計算'區域平均值'和用於計算平均值的樣本數。它與平均值很好地工作,但是當我想計算樣本「數」的數量時,它「平均」給出了相同的結果。我也用''min''也給出了相同的結果。爲什麼Zonal中的樂趣給出了「min」,「mean」,「count」的相同結果?

 Library (raster) 
     Library (rasterVis) 
     Library (lattic) 
    r <- raster(nrows=10, ncols=10) 
    r <- setValues(r, 1:ncell(r)) 
    r1 <- raster(nrows=10, ncols=10) 
    r1 <- setValues(r1, 1:ncell(r)) 
    St=stack(r,r1) 
    idx <- seq(as.Date('2008-01-15'), as.Date('2008-1-16'), 'day') 
    SISmm <- setZ(St, idx) 
    dirLayer <- init(SISmm, v='y') 
z <- zonal(SISmm, dirLayer, FUN='mean', digits=2) ## worked fine 
zc <- zonal(SISmm, dirLayer, FUN='count',na.rm=T, digits=2)## the results are the same as z 
zsd <- zonal(SISmm, dirLayer, FUN='sd',na.rm=T, digits=2)## the results are the same as z 

請幫忙嗎?

+0

我對它爲什麼可能失敗有想法,但是你沒有包含足夠的代碼來加載具有這些不同功能的包。 –

回答

1

主要錯誤是參數名稱是fun而不是FUN。 (在包的早期版本的說法是stat。這麼多的向後兼容性)

您將有問題count,這是有利於freq提倡的,這需要一個raster -ish對象,但只要我可以告訴zonal將數據轉換爲numeric之後再將其傳遞給被調用的函數。可能你可以做zonal(SISmm, dirLayer, stat=function(k) freq(as.raster(k)),但我還沒有嘗試過。

+0

好吧,我對運行和舊版本的rasterraster感到羞恥。我會盡快給您回覆。 - >>'樂趣'不一樣'FUN' –

+0

@hyat圖什麼出來?參數名稱區分大小寫。 –

+0

@hyat最後的機會:你認爲你在哪裏「算」?沒有這樣的外部功能。 –

相關問題