Hi guys,

Everytime I tried to run calc(), R crashed. Any advice?
Here is my code:

#clear memory/remove all R objects
rm(list=ls())

#check memory size and set memory limit
memory.size()
memory.limit(10000)

#Load related packages library
library(raster)
library(rgdal)

#Load all raster data in a folder
img <- list.files(pattern='\\.img$')

#Check rasters
list(img)

#Stack layers into one file
flag7 <- stack(img)

#2 CReate fun
time <- 1:nlayers(flag7)
fun <- function(x) {
if (all(is.na(x))) {
return(cbind(NA,NA,NA))
}
xcost<-cos(2*pi*time/366)
xsine<-sin(2*pi*time/366)
m = lm(x~xcost+xsine)
s  <- summary(m)
maxval <- max(predict(m))
r2 <- s$r.squared
sigma <- s$sigma
cbind(maxsst, r2, sigma)
}

#3 Run function with rasterstack
r <- calc(flag7, fun)

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to