**Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 account
2017.4137 180.8861 103.03618 258.7361 61.8249012 299.9474 R00172
2017.4164 181.3260 102.63465 260.0173 60.9779946 301.6739 R00172
2017.4192 181.7658 102.24090 261.2906 60.1429756 303.3886 R00172
2017.4219 182.2056 101.85468 262.5565 59.3194730 305.0917 R00172
2017.4247 182.6454 101.47575 263.8151 58.5071341 306.7837 R00172
2017.4274 183.0852 101.10391 265.0665 57.7056233 308.4648 R00172**
以下输出如下
我的要求是转换此2017.4137,2017.4164,2017.4192.........
进入日期格式。
esw<-rownames(df2)
> esw
[1] "2017.4137" "2017.4164" "2017.4192" "2017.4219" "2017.4247" "2017.4274"
[7] "2017.4301" "2017.4329" "2017.4356" "2017.4384" "2017.4411" "2017.4438"
[13] "2017.4466" "2017.4493" "2017.4521" "2017.4548" "2017.4575" "2017.4603"
[19] "2017.4630" "2017.4658" "2017.4685" "2017.4712" "2017.4740" "2017.4767"
[25] "2017.4795" "2017.4822" "2017.4849" "2017.4877" "2017.4904" "2017.4932"
我无法获得日期格式
df2$dates<-as.Date(esw,format="%Y/%m/%d")
df2$dates<-as.Date(esw,format="%Y/%m/%d")
> df2$dates
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[31] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[61] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
[91] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
我得到了所有的NA。 有人可以帮我进一步了解吗?
由于
答案 0 :(得分:1)
以下是使用lubridate将esw转换为日期时间格式的方法:
esw <- c("2017.4137", "2017.4164", "2017.4192" , "2017.4219", "2017.4247", "2017.4274",
"2017.4301", "2017.4329", "2017.4356" , "2017.4384" , "2017.4411" , "2017.4438",
"2017.4466", "2017.4493", "2017.4521", "2017.4548", "2017.4575" , "2017.4603" ,
"2017.4630", "2017.4658", "2017.4685" , "2017.4712" , "2017.4740" , "2017.4767" ,
"2017.4795", "2017.4822", "2017.4849" , "2017.4877" , "2017.4904" , "2017.4932")
esw <- as.numeric(esw)
library(lubridate)
format(date_decimal(esw), "%Y-%m-%d %H:%M:%S")
[1] "2017-06-01 00:00:43" "2017-06-01 23:39:50" "2017-06-03 00:11:31" "2017-06-03 23:50:38" "2017-06-05 00:22:19"
[6] "2017-06-06 00:01:26" "2017-06-06 23:40:33" "2017-06-08 00:12:14" "2017-06-08 23:51:21" "2017-06-10 00:23:02"
[11] "2017-06-11 00:02:09" "2017-06-11 23:41:16" "2017-06-13 00:12:57" "2017-06-13 23:52:04" "2017-06-15 00:23:45"
[16] "2017-06-16 00:02:52" "2017-06-16 23:41:59" "2017-06-18 00:13:40" "2017-06-18 23:52:47" "2017-06-20 00:24:28"
[21] "2017-06-21 00:03:35" "2017-06-21 23:42:43" "2017-06-23 00:14:23" "2017-06-23 23:53:31" "2017-06-25 00:25:11"
[26] "2017-06-26 00:04:19" "2017-06-26 23:43:26" "2017-06-28 00:15:07" "2017-06-28 23:54:14" "2017-06-30 00:25:55"
如果您只想要日期,没有时间,请小心,因为年份分数可能导致重复日期。在这种情况下,2017年6月1日
format(date_decimal(esw), "%Y-%m-%d")
[1] "2017-06-01" "2017-06-01" "2017-06-03" "2017-06-03" "2017-06-05" "2017-06-06" "2017-06-06" "2017-06-08" "2017-06-08"
[10] "2017-06-10" "2017-06-11" "2017-06-11" "2017-06-13" "2017-06-13" "2017-06-15" "2017-06-16" "2017-06-16" "2017-06-18"
[19] "2017-06-18" "2017-06-20" "2017-06-21" "2017-06-21" "2017-06-23" "2017-06-23" "2017-06-25" "2017-06-26" "2017-06-26"
[28] "2017-06-28" "2017-06-28" "2017-06-30"