【发布时间】:2017-07-06 22:22:40
【问题描述】:
如何将日期转换为从 1 开始的连续变量。我尝试使用 as.numeric 但 R 从默认的 1970 年 1 月 1 日开始计数,而我的数据从 2009 年 10 月 7 日开始。
我需要进行此转换以在两个 x 轴(1 和 3)上绘制日期。
plot(LAI~Date, data=LAI_simulation)
LAI_simulation$Date<- as.numeric(LAI_simulation$Date,origin="2009-10-07")
#R does not see the origin
axis.Date(side=3,at=LAI_simulation$Date)
# also tried seq
dates <- seq(LAI_simulation$Date[1, "2009-10-07"], LAI_simulation$Date[nrow(LAI_simulation$Date), "2010-10-07"], by = "days")
感谢您的帮助。
【问题讨论】:
-
只需减去基准日期,然后像
LAIsimulation$index <- as.integer(LAI_simulation$Date - as.Date("2009-10-06"))一样转换。 -
感谢为我工作。