【发布时间】:2019-08-27 03:37:22
【问题描述】:
对于栅格堆栈中超过 1000 个栅格的时间序列分析,我需要日期。文件结构中的数据几乎是每周一次 “... 1981036 .... tif” 零分隔年份和星期 我需要类似:“1981-36”
但总是得到错误 charToDate (x) 中的错误:字符串不是标准的明确格式
library(sp)
library(lubridate)
library(raster)
library(Zoo)
raster_path <- ".../AVHRR_All"
all_raster <- list.files(raster_path,full.names = TRUE,pattern = ".tif$")
all_raster
带给我: all_raster
".../VHP.G04.C07.NC.P1981036.SM.SMN.Andes.tif"
".../VHP.G04.C07.NC.P1981037.SM.SMN.Andes.tif"
".../VHP.G04.C07.NC.P1981038.SM.SMN.Andes.tif"
…
为了获取年份和相关的星期,我使用了以下代码:
timeline <- data.frame(
year= as.numeric(substr(basename(all_raster), start = 17, stop = 17+3)),
week= as.numeric(substr(basename(all_raster), 21, 21+2))
)
timeline
带给我: 时间线
year week
1 1981 35
2 1981 36
3 1981 37
4 1981 38
…
但我需要像 = "1981-35" 这样的东西才能在以后绘制我的时间序列
我试过了:
timeline$week <- as.Date(paste0(timeline$year, "%Y")) + week(timeline$week -1, "%U")
并得到错误:charToDate(x) 中的错误:字符串不是标准的明确格式
或者我试过了
fileDates <- as.POSIXct(substr((all_raster),17,23), format="%y0%U")
得到同样的错误
【问题讨论】:
-
检查这个也许它会帮助你[stackoverflow.com/questions/55007079/…
-
我必须将分隔的零转换为“-”吗?所以从“1981035”->“1981-35”
标签: r time-series as.date