Hello All, I am attempting to reproduce the bioclimatic (Worldclim, Hijmans et al 2005) variables with the raster package and I am stuck on the group "temp of driest quarter" etc. variables. I am attempting it with the function "overlay" ("raster" package).
Here is how it looks: # To know the first month of the wettest quarter maxmonth<- function(a,b,d,e,f,g,i,j,k,l,m,n){ o<- sum(c(a,b,d)) p<- sum(c(b,d,e)) r<- sum(c(d,e,f)) u<- sum(c(e,f,g)) v<- sum(c(f,g,i)) w<- sum(c(g,i,j)) x<- sum(c(i,j,k)) y<- sum(c(j,k,l)) z<- sum(c(k,l,m)) aa<- sum(c(l,m,n)) ab<- sum(c(m,n,a)) ac<- sum(c(n,a,b)) ad<- which.max(c(o,p,r,u,v,w,x,y,z,aa,ab,ac)) return(ad)}
maxmonth(a=13,b=16,d=41,e=61,f=41,g=16,i=15,j=14,k=13,l=11,m=31,n=11)
# works: 2nd element (month) is the beginning of the wettest quarter [1] 2 mon_stac<- stack(paste(pc_clim,"",y,"_prec",1:12,".asc", sep="")) # Now attempt it avg<- overlay(mon_stac, fun=maxmonth) Error in .overlayList(rasters, fun = fun, filename = filename, ...) : cannot use this formula; lenghts do not match # How about manually? a<- raster(paste(pc_clim,"",y,"_prec",1,".asc", sep="")) b<- raster(paste(pc_clim,"",y,"_prec",2,".asc", sep="")) d<- raster(paste(pc_clim,"",y,"_prec",3,".asc", sep="")) e<- raster(paste(pc_clim,"",y,"_prec",4,".asc", sep="")) f<- raster(paste(pc_clim,"",y,"_prec",5,".asc", sep="")) g<- raster(paste(pc_clim,"",y,"_prec",6,".asc", sep="")) i<- raster(paste(pc_clim,"",y,"_prec",7,".asc", sep="")) j<- raster(paste(pc_clim,"",y,"_prec",8,".asc", sep="")) k<- raster(paste(pc_clim,"",y,"_prec",9,".asc", sep="")) l<- raster(paste(pc_clim,"",y,"_prec",10,".asc", sep="")) m<- raster(paste(pc_clim,"",y,"_prec",11,".asc", sep="")) n<- raster(paste(pc_clim,"",y,"_prec",12,".asc", sep="")) avg<- overlay(a,b,d,e,f,g,i,j,k,l,m,n, fun=maxmonth) Error in .overlayList(rasters, fun = fun, filename = filename, datatype = datatype, : cannot use this formula; lenghts do not match Also doesn't work...
length(mon_stac[1])
[1] 12 I have 12 rasters being fed into overlay, but it won't buy it. I think that my first step is to know the first month of the wettest month. Once I can do that I can do it for temperature as well. Thanks and Regards, Brian _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo