我有一个xts
包含一年降水数据的系列:
str(data_prec)
An ‘xts’ object from 2011-01-01 to 2011-12-31 23:55:00 containing:
Data: num [1:105125, 1] 0 0 0 0 0 0 0 0 0 0 ...
Indexed by objects of class: [POSIXct,POSIXt] TZ:
xts Attributes:
List of 2
$ tclass: chr [1:2] "POSIXct" "POSIXt"
$ tzone : chr ""
部分数据如下:
2011-12-15 05:15:00, 0
2011-12-15 05:20:00, 0
2011-12-15 05:25:00, 0.1
2011-12-15 05:30:00, 1.2
2011-12-15 05:31:00, 0.2
2011-12-15 05:32:00, 0.6
2011-12-15 05:33:00, 0.1
2011-12-15 05:35:00, 0.1
2011-12-15 05:36:00, 0
2011-12-15 05:37:00, 0.6
2011-12-15 05:40:00, 0
2011-12-15 05:45:00, 0
2011-12-15 05:50:00, 0.1
我需要通过汇总以前的数据每五分钟获取一次数据。我尝试过使用aggregate
,to.minutes5
但merge
没有成功。我不知道我做错了什么。这是我到达的最接近的方式:
align.time(period.sum(data_prec,endpoints(data_prec,"minutes",k=5)),300)
那给了我:
2011-12-15 05:15:00, 0
2011-12-15 05:20:00, 0
2011-12-15 05:25:00, 0
2011-12-15 05:30:00, 0.1
2011-12-15 05:35:00, 2.1
2011-12-15 05:40:00, 0.7
2011-12-15 05:45:00, 0
2011-12-15 05:50:00, 0
2011-12-15 05:55:00, 0.1
2011-12-15 06:00:00, 0
这就是我要找的:
2011-12-15 05:15:00, 0
2011-12-15 05:20:00, 0
2011-12-15 05:25:00, 0.1
2011-12-15 05:30:00, 1.2
2011-12-15 05:35:00, 1.0
2011-12-15 05:40:00, 0.6
2011-12-15 05:45:00, 0
2011-12-15 05:50:00, 0.1
2011-12-15 05:55:00, 0
2011-12-15 06:00:00, 0
感谢您的任何建议。