如何按时间顺序聚合数据?
我有一个问题,真的需要你的帮助吗?我的数据(让我们将其命名为“日期”)如下所示:
location date value
1 2010-01-01 6.4
1 2010-01-02 5.7
.
.
2 2010-01-01 0.8
2 2010-01-02 2.5
2 2010-01-03 5.5
我想聚合 3 周期间内的位置数据(值)?我已经尝试使用包 timeSeries 但它不起作用?
by1 <- timeSequence(from = "2009-12-30", to = "2010-12-29", by= "4 week")
by1
aggregate(date, by=list(by1, date$location), sum)
I have a problem and would really need your help? My data (let's name it "date") looks like this:
location date value
1 2010-01-01 6.4
1 2010-01-02 5.7
.
.
2 2010-01-01 0.8
2 2010-01-02 2.5
2 2010-01-03 5.5
I would like to aggregate data (value) on location and on 3 weeks period? I have already try to use package timeSeries but it is not working?
by1 <- timeSequence(from = "2009-12-30", to = "2010-12-29", by= "4 week")
by1
aggregate(date, by=list(by1, date$location), sum)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是一种使用
seq.Date
生成断点、cut
来存储数据以及ddply
进行总结的方法:结果:
Here is an approach using
seq.Date
to generate the break points,cut
to bin your data, andddply
to summarize:The results:
使用
lubridate
,您可以用一行代码编写此代码。Using
lubridate
, you can write this with a one-liner.