3
添加缺少次行我有一个大的数据集,看起来像:我想填补缺失的时间步长(YYYY-MM-DD HH:MM:SS)由R中
Time,Volume
1996-02-05 00:34:00,0.01
1996-02-05 00:51:00,0.01
1996-02-05 00:52:00,0.01
1996-02-05 01:04:00,0.01
1996-02-05 01:19:00,0.01
1996-02-05 05:00:00,0.01
1996-02-05 05:07:00,0.01
1996-02-05 05:08:00,0.01
1996-02-05 05:14:00,0.01
对每个30分钟的时间间隔总结Volume
列。这是我已经试过:
z <- read.zoo("precip.csv", header = TRUE, sep = ",", FUN = as.chron)
half_hour <- period.apply(z, endpoints(z, "minutes", 30), length)
其中返回:
Time,Volume
02/05/96 00:52:00,3
02/05/96 01:19:00,2
02/05/96 05:14:00,4
我想要得到的输出看起来像:
Time,Volume
02/05/96 00:29:00,0
02/05/96 00:59:00,3
02/05/96 01:29:00,2
02/05/96 01:59:00,0
02/05/96 02:29:00,0
02/05/96 02:59:00,0
...等等。
另外,我想如果我能在原始数据集,使每分钟是占补(其中失踪Volumes
等于0),这是可行的。
我发现this post,但不能使它工作。
> z_xts<- xts(precip[,c("Volume")],precip[,"Time"])
Error in xts(precip[, c("Volume")], precip[, "Time"]) :
order.by requires an appropriate time-based object
谢谢!我正在此错误消息在步骤4:>一< - align.time(米,60 * 30) 错误UseMethod(“align.time”): 关于“align.time”不适用方法应用于对象类“动物园” – user2263130 2013-04-10 21:50:03
@ user2263130的:那是因为你转换'M'到动物园对象,而不是把它当作一个XTS的对象。 'align.time'仅适用于XTS对象,因为动物园的对象,不能保证被时间索引(它们可以被任何真实下令进行索引)。 – 2013-04-10 22:02:54
啊!非常感谢你! – user2263130 2013-04-10 22:03:32