如何在多个条件下溶解数据集-R
考虑数据集以下数据集:
ID | 启动时间 | 结束时间 | 流量 | 车道 |
---|---|---|---|---|
1 | 01-01-2015 | 01-02-2015 | 500 | 1 |
1 1 | 01-01-01-2015 | 01-02-2015 | 400 | 2 |
1 | 01-02-02-2015 | 01-01-03-201515-201515-2015 | 250 | 1 |
1 | 01-02-2015 | 01-03-2015 | 250 | 2 2 |
2 | 01-01-01-2015 | 01-02-2015 | 80 | 1 |
2 | 01-02-02-2015 | 01-03-03-2015 | 70 | 1 |
我想基于流量基于交通价值多种条件。流量值应基于类似的id
和开始
时间汇总,以便输出数据集变为:
ID | 启动时间 | 结束时间 | 流量 |
---|---|---|---|
1 | 01-01-01-2015 | 01-02 -2015 | 900 |
1 | 01-02-2015 | 01-03-2015 | 500 |
2 | 01-01-2015 | 01-02-2015 | 80 |
2 | 01-02-2015 | 01-03-03-2015 | 70 70 |
什么是一种方便的实现方式?
Consider dataset the following dataset:
ID | Start time | End time | Traffic | Lane |
---|---|---|---|---|
1 | 01-01-2015 | 01-02-2015 | 500 | 1 |
1 | 01-01-2015 | 01-02-2015 | 400 | 2 |
1 | 01-02-2015 | 01-03-2015 | 250 | 1 |
1 | 01-02-2015 | 01-03-2015 | 250 | 2 |
2 | 01-01-2015 | 01-02-2015 | 80 | 1 |
2 | 01-02-2015 | 01-03-2015 | 70 | 1 |
I want to aggregate the traffic values based on multiple conditions. The traffic values should be aggregated based on a similar ID
and Start
time so that the output dataset becomes:
ID | Start time | End time | Traffic |
---|---|---|---|
1 | 01-01-2015 | 01-02-2015 | 900 |
1 | 01-02-2015 | 01-03-2015 | 500 |
2 | 01-01-2015 | 01-02-2015 | 80 |
2 | 01-02-2015 | 01-03-2015 | 70 |
What is a convenient way of achieving this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该通过对
group_by()
进行分组,然后总结
,例如You should achieve this by grouping
group_by()
and thensummarize
accordingly, e.g.