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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to