I have a raster stack for climate data where each layer represents a measure of daily precipitation. The names of each layer are long and include the month, year, and day each layer represents.
prcpSmall
class : RasterStack
dimensions : 790, 812, 641480, 6 (nrow, ncol, ncell, nlayers)
resolution : 1000, 1000 (x, y)
extent : 1590250, 2402250, 149500, 939500 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=lcc +lat_1=25 +lat_2=60 +lat_0=42.5 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs
names : FIA_DAYME//03.2015.10, FIA_DAYME//03.2015.11, FIA_DAYME//03.2015.12, FIA_DAYME//03.2015.13, FIA_DAYME//03.2015.14, FIA_DAYME//03.2015.15
For example, data in the first layer were collected on March 10th, 2015. But, when I use the names()
the time stamp is gone.
names(prcpSmall)
[1] "FIA_DAYMET_prcp_2003.2015.10" "FIA_DAYMET_prcp_2003.2015.11"
[3] "FIA_DAYMET_prcp_2003.2015.12" "FIA_DAYMET_prcp_2003.2015.13"
[5] "FIA_DAYMET_prcp_2003.2015.14" "FIA_DAYMET_prcp_2003.2015.15"
The complete dataset include over 4000 layers. Is there a way I access the full layer name with the time stamp information for each layer?
Thanks!
You only show a few days for one month, but from the example you provide, it would seem that you can do:
# n <- names(prcpSmall)
n <- c("FIA_DAYMET_prcp_2003.2015.10", "FIA_DAYMET_prcp_2003.2015.11", "FIA_DAYMET_prcp_2003.2015.12", "FIA_DAYMET_prcp_2003.2015.13", "FIA_DAYMET_prcp_2003.2015.14", "FIA_DAYMET_prcp_2003.2015.15")
d <- gsub("FIA_DAYMET_prcp_20", "", n)
as.Date(d, "%m.%Y.%d")
# [1] "2015-03-10" "2015-03-11" "2015-03-12" "2015-03-13" "2015-03-14" "2015-03-15"