Skip to content
Prev 23538 / 29559 Next

Convert rasters to data frame with time stamp

I don't think I completely understand but can you use tidyr::gather to get
what you want? if you have multiple datasets you could join them all
together at the end.

library(raster)
library(tidyr)

#Create a rasterStack similar to my data - same dimensions and layer names
r <- raster(ncol=60, nrow=60)
s <- stack(lapply(1:408, function(x) setValues(r, runif(ncell(r)))))
names(s) <- paste0('X', seq(as.Date("1980/1/1"), by = "month", length.out =
408))
s
dF=as.data.frame(s)
dF2=gather(dF,date)



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