[R-sig-Geo] questions on RasterStack/Brick

Robert Hijmans r.hijmans at gmail.com
Sat Jul 30 00:53:15 CEST 2011


> Apologies-- there was an error in the stack correlation function of my
> last post. Below is an updated 
> version of the function.   

Thanks Logan, 
That is very useful, but I would not use stackApply, but the simpler calc.
Below a reworked version of your function:


stackcor <- function(s1, s2, method='spearman') {
	mycor <- function(v) {
		x <- v[1:split]
		y <- v[(split+1):(2*split)]
		cor(x, y, method=method)
	}
	s <- stack(s1, s2)
	split <- nlayers(s)/2
	calc(s, fun=mycor )
}

Best, Robert

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/questions-on-RasterStack-Brick-tp5553580p6635224.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list