r - How to apply simple code for a vector to several rasters? -
i have 12 binary (raster) files . calculate moving average 12 values each pixel in 12 files.
for simple vector can moving average using :
x <- c(1,2,3,na,na,4,6,5,6,4,2,5) movingmean <- rollapply(x, 3, fun = mean, na.rm = t,fill=na)
now want same rasters , tried:
files <- list.files("c:final-2010", "*.envi", full.names = true) results <- list() (.files in files) { # read in 12 files vector of numbers # take average of x <- do.call(rbind,(lapply(.files, readbin , double() , size = 4 ,n =1440 * 720 , signed = t))) # take moving average across 12 values # 12 files each pixel results[[length(results) + 1l]] <- rollapply(x, 3, fun = mean,na.rm = t) }
but got error:
error in seq.default(start.at, nrow(data), = by) : wrong sign in 'by' argument
maybe work
results <- overlay(stack(files), fun=function(x) movingfun(x, fun=mean, n=3, na.rm=true))
r binary raster moving-average
No comments:
Post a Comment