Change maxsst to maxval and it works fine with small rasterstack.

With 1000 rows x 1000 cols x 5000 nlayers, the code failed.

Amybody willing to help?
On 17 Feb 2014 19:19, "Eddie Smith" <eddieatr@gmail.com> wrote:

> 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]]

