0

我有 12 个二进制(光栅)文件。我想计算 12 个文件中每个像素的 12 个值的移动平均值。

对于一个简单的向量,我们可以使用以下方法获得移动平均值:

         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)

现在我想做同样的事情,但使用栅格,我尝试过:

files   <- list.files("C:final-2010", "*.envi", full.names = TRUE)
results <- list()
for (.files in files) {
    # read in the 12 files as a vector of numbers 
    # that we take the average of
    x <- do.call(rbind,(lapply(.files, readBin  , double() , 
                     size = 4 ,n =1440 * 720 , signed = T)))
    # take the moving average across the 12 values 
    # from the 12 files for each pixel
    results[[length(results) + 1L]] <- rollapply(x, 3, FUN = mean,na.rm = T)
}

但是得到了这个错误:

    Error in seq.default(start.at, NROW(data), by = by) : 
                             wrong sign in 'by' argument
4

1 回答 1

1

也许这样的事情会起作用

results <- overlay(stack(files), fun=function(x) 
                   movingFun(x, fun=mean, n=3, na.rm=TRUE))
于 2013-02-13T21:41:10.393 回答