【发布时间】:2019-03-18 15:43:24
【问题描述】:
我尝试在此处插入这个meterValue,完整的csv:https://drive.google.com/open?id=18cwtw-chAB-FqqCesXZJ-6NB6eHFJlgQ
localminute,dataid,meter_value
2015-10-03 09:51:53,6578,157806
2015-10-13 13:41:49,6578,158086
:
:
2016-01-17 16:00:33,6578,164544 #end of meter_value data for ID=6578
基于@G. Grothendieck,建议,我在 z.interpolate(合并数据)时遇到错误
D6578z <- read.csv.zoo("test_6578.csv")[,2]
D6578zd <- to.daily(D6578z)[,4]
#Warning messages:
#1: In zoo(xx, order.by = index(x), ...) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique
#2: In zoo(rval, index(x)[i]) :some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique
test_6578t <- time(D6578zd)
plot(D6578zd,type="p",xaxt="n", pch=19, col="blue",cex=1.5)
diff(test_6578t)
t.daily6578 <- seq(from =min(test_6578t),to=max(test_6578t),by="1 day")
dummy6578 <- zoo(,t.daily6578)
z.interpolated <- merge(D6578zd,dummy6578,all=TRUE)
*#Error in merge.zoo(D6578zd, dummy6578, all = TRUE) : series cannot be merged with non-unique index entries in a series*
@G提供的插值数据中R代码一小时时差的解决方法。格洛腾迪克,如下。
嗨@G。 Grothendieck,感谢您提供解决方案代码。关于您的代码,我有一些问题要向您澄清。
`line1: to.hour <- function(x) as.POSIXct(trunc(as.POSIXct(x, origin = "1970-01-01"), "hour"))
line2: z <- read.csv.zoo("test_6578.csv", FUN = to.hour, aggregate = function(x) tail(x, 1))`
`line3: zz <- na.approx(as.zoo(as.ts(z)))`
`line4: time(zz) <- as.POSIXct(time(zz), origin = "1970-01-01")`
在第 1 行,为什么在 `trunc(as.POSIXct(x,origin =”1970-01-01”)?
我知道“trunc”函数会四舍五入日期时间值。在第 2 行中,这段代码是什么意思“FUN=to.hour, aggregate =函数(x)尾(x,1)”工作?
因为我不明白什么是tail(x,1)。我提取了
zcsv文件中的函数,我观察到只有dataid和meter_value 使用“read.csv.zoo”函数时会生成列。在第 3 行,我了解到,
zz函数提供了插值数据 但我没有完全理解代码“na.approx(as.zoo(as.ts(z)))”, 因为z已经是read.csv.zoo之后的动物园系列,为什么我们还有 在“na.approx”行中使用“as.zoo”和“as.ts”?zoo 和 zooreg 系列有什么区别?
第4行,“time(zz)”是“zz”函数的索引?
提前感谢您的解释。
【问题讨论】:
标签: r time-series forecasting