我试图在使用 plot() 之前将矩阵的元素从 Excel 序列日期转换为 Date 对象的向量。
我可以创建一个向量并得到预期的结果:
library(chron)
# set date origin as defined in Excel
options(chron.origin = c(month=1, day=1, year=1900))
test_dates <- c(40917:40920)
test_dates
## [1] 40917 40918 40919 40920
chron(test_dates, out.format = "m/d/y")
## [1] 01/11/12 01/12/12 01/13/12 01/14/12
但是当我尝试在我的实际向量上使用它时,它不起作用
# first 10 vlaues in vector
pivot_pred$date
## [1] 40917 40918 40919 40920 40921 40922 40923 40924 40925 40926...
chron(pivot_pred$date, out.format = "m/d/y")
## Error in chron(dates. = floor(dts), times. = tms, format = format, out.format = out.format, :
misspecified chron format(s) length
我敢肯定这很简单,但我尝试了很多变体,但都没有奏效。关于我做错了什么有什么建议吗?