Skip to content
Prev 23539 / 29559 Next

Convert rasters to data frame with time stamp

RasterStack or RasterBrick are always a matrix, with the rows
representing cells, and the columns representing layers"  ....so all
you have to do is transpose the matrix from getValues, cbind the date
column, do your analysis.  To go back to raster again just drop the
names/date column, convert to matrix, transpose, and do setValues.

So for your example (untested...will need checking):
R> s_t <- t(s)
R> df_s_t <- cbind(names(s),as.data.frame(s_t))
R> # do your analysis
R> # To do the reverse
R> m <- as.matrix(df_s_t[,-1])
R> mt <- t(m)
R> setValues(s,mt)

HTH,
Vijay.

On Fri, Oct 16, 2015 at 4:39 PM, Thiago V. dos Santos
<thi_veloso at yahoo.com.br> wrote: