Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have several rasters that I want to do some calculations ,basically calculating the moving average.

        dir2 <- list.files("D:\\2010+2011", "*.bin", full.names = TRUE)
       saf=stack(dir2)
      movi <-  overlay(stack(saf),fun=function(x) movingFun(x, fun=mean, n=3,  na.rm=TRUE))
         Error in .overlayList(x, fun = fun, filename = filename, ...) : 
     cannot use this formula, probably because it is not vectorized

I then checked the data but found that all values were returnd as NA and this may explain why i am getting the error.

    saf
   class       : RasterStack 
   dimensions  : 720, 1440, 1036800, 601  (nrow, ncol, ncell, nlayers)
   resolution  : 0.25, 0.25  (x, y)
   extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
 names       : Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84,    Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, , ... 
min values  :                    NA,                    NA,                    NA,                       NA,                    NA,                    NA,                    NA,                     NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA, ... 
max values  :                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                    NA,                       NA,                    NA,                    NA,                    NA, ... 

I wonder why this is happening, I checked the files separably(summary) and everything was right!as you can see bellow:

          summary(saf)
         ol_025_H14_2011092000_1_wgs84 Vol_025_H14_2011092100_1_wgs84   Vol_025_H14_2011092200_1_wgs84 Vol_025_H14_2011092300_1_wgs84 Vol_025_H14_2011092400_1_wgs84
  Min.                           0.00000                      0.0000000                            0.0000000                      0.0000000                      0.0000000
 1st Qu.                        0.31883                      0.3163167                      0.3146436                      0.3113111                      0.3064551
 Median                      9999.00000                   9999.0000000                   9999.0000000                   9999.0000000                   9999.0000000
 3rd Qu.                     9999.00000                   9999.0000000                   9999.0000000                   9999.0000000                   9999.0000000
  Max.                        9999.00000                   9999.0000000                   9999.0000000                   9999.0000000                   9999.0000000
 NA's                           0.00000                      0.0000000                        0.0000000                      0.00000

I am gratful to anyhelp

share|improve this question
    
Have you calculated statistics on your output (help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…)? Sometimes you need to do this manually before you can get sensible summaries. –  MappaGnosis Mar 19 '13 at 21:29
    
why are you doing 2 times stack ? –  A.R Apr 5 '13 at 16:15

1 Answer 1

up vote 1 down vote accepted

The NA's here refer to the fact that the min and max value are unknown (this is no longer the case in the current version of 'raster'). Your function should work if you use 'calc' instead of 'overlay'

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.