I am using this code to calculate the moving average mean.It worked fine but
when I wanted to also calculate based on sd(stander deviation) I got the
error shown below.
I read this documentation of R movingFun and found that sd was mentioned at
http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/raster/html/movingFun.html
I wonder if needs any other things to conseder or sd is not at all supplied
by this function.
sami<- list.files("C:\\Usersfinal-2010", "*.envi",
full.names = TRUE)
saf=stack(sami)
dm <- overlay(saf ,fun=function(x) movingFun(x, fun=mean, n=3,
na.rm=TRUE,fill=NA))
### worked very well
ds <- overlay(saf ,fun=function(x) movingFun(x, fun= sd, n=3,
na.rm=TRUE))
### did not work
Error in .overlayList(x, fun = fun, filename = filename, ...) :
cannot use this formula, probably because it is not vectorized
> saf
class : RasterStack
dimensions : 720, 1440, 1036800, 12 (nrow, ncol, ncell, nlayers)
resolution : 0.25, 0.25 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84
+towgs84=0,0,0
names : SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast,
SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast,
SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast,
SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast, SM_RE01_M//7_amenlast,
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-get-the-rolling-standard-deviation-in-rasters-tp4661819.html
Sent from the R help mailing list archive at Nabble.com.
Peter Ehlers
2013-Mar-19 15:15 UTC
[R] How to get the rolling standard deviation in rasters?
On 2013-03-19 06:41, Jonsson wrote:> I am using this code to calculate the moving average mean.It worked fine but > when I wanted to also calculate based on sd(stander deviation) I got the > error shown below. > I read this documentation of R movingFun and found that sd was mentioned at > http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/raster/html/movingFun.html > > I wonder if needs any other things to conseder or sd is not at all supplied > by this function. > > sami<- list.files("C:\\Usersfinal-2010", "*.envi", full.names = TRUE)We're not sitting at your computer, so the above line is useless information.> saf=stack(sami) > dm <- overlay(saf ,fun=function(x) movingFun(x, fun=mean, n=3, > na.rm=TRUE,fill=NA)) > ### worked very well > > ds <- overlay(saf ,fun=function(x) movingFun(x, fun= sd, n=3, > na.rm=TRUE)) > ### did not work > > Error in .overlayList(x, fun = fun, filename = filename, ...) : > cannot use this formula, probably because it is not vectorized[...snip...] This suggests that it might be useful to read ?Vectorize. Peter Ehlers