[R-sig-Geo] How to calculate slope in rasterbrick

Robert Hijmans r.hijmans at gmail.com
Wed Jun 15 20:00:36 CEST 2011


> I have a brick that contains 348 layers. Each layer is small in 
> dimension ncol=69, nrow=43. My question is, how do I calculate slopes 
> for each pixels from layer 1 to layer 348(Month one to months 348). I 
> am trying to find the trend as I am working with time series data. 


for RasterBrick 'b'

time <- 1:nlayers(b)
fun <- function(x) { lm(x ~ time)$coefficients[2] }
x <- calc(b, fun)

x is a RasterLayer with the slope of a linear regression model for each
cell.

Robert


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/How-to-calculate-slope-in-rasterbrick-tp6478027p6479946.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list