【发布时间】:2015-09-16 01:48:48
【问题描述】:
我知道有几个相关的问题,但我似乎在这里的某个地方磕磕绊绊。我尽我所能地关注了这个帖子:Interpolating timeseries,但收到错误消息(见下文):
我的数据集包含每天每四个小时收集一次的样本。我想将这些数据插入每小时值。下面是我更大数据集的一个子样本:
vis <- structure(list(datetime = structure(1:24, .Label = c("2002-05-01-00",
"2002-05-01-06", "2002-05-01-12", "2002-05-01-18", "2002-05-02-00",
"2002-05-02-06", "2002-05-02-12", "2002-05-02-18", "2002-05-03-00",
"2002-05-03-06", "2002-05-03-12", "2002-05-03-18", "2002-05-04-00",
"2002-05-04-06", "2002-05-04-12", "2002-05-04-18", "2002-05-05-00",
"2002-05-05-06", "2002-05-05-12", "2002-05-05-18", "2002-05-06-00",
"2002-05-06-06", "2002-05-06-12", "2002-05-06-18"), class = "factor"),
VIStot = c(0L, 128L, 359L, 160L, 1L, 121L, 316L, 162L, 1L,
132L, 339L, 163L, 2L, 137L, 364L, 155L, 3L, 122L, 345L, 179L,
3L, 125L, 147L, 77L)), .Names = c("datetime", "VIStot"), class = "data.frame", row.names = c(NA,
-24L))
我插入到每小时分辨率的代码如下:
vis[, c(2)] <- sapply(vis[, c(2)], as.numeric)
library(zoo)
vis$datetime <- as.POSIXct(vis$datetime, format="%Y-%m-%d-%H")
hr <- zoo(vis$VIStot, vis$datetime)
int <- na.spline(hr$VIStot)
这以错误消息结束
$.zoo(hr, VIStot) 中的错误:单变量动物园系列不可能
我没有正确格式化日期时间吗?为什么hr 不能同时读取VIStot 和datetime?
此外,一旦插值,我想以 .csv 文件格式导出值。
【问题讨论】:
标签: r interpolation