如何在多个条件下溶解数据集-R

发布于 2025-01-25 04:52:03 字数 1301 浏览 5 评论 0原文

考虑数据集以下数据集:

ID启动时间结束时间流量车道
101-01-201501-02-20155001
1 101-01-01-201501-02-20154002
101-02-02-201501-01-03-201515-201515-20152501
101-02-201501-03-20152502 2
201-01-01-201501-02-2015801
201-02-02-201501-03-03-2015701

我想基于流量基于交通价值多种条件。流量值应基于类似的id开始时间汇总,以便输出数据集变为:

ID启动时间结束时间流量
101-01-01-201501-02 -2015900
101-02-201501-03-2015500
201-01-201501-02-201580
201-02-201501-03-03-201570 70

什么是一种方便的实现方式?

Consider dataset the following dataset:

IDStart timeEnd timeTrafficLane
101-01-201501-02-20155001
101-01-201501-02-20154002
101-02-201501-03-20152501
101-02-201501-03-20152502
201-01-201501-02-2015801
201-02-201501-03-2015701

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:

IDStart timeEnd timeTraffic
101-01-201501-02-2015900
101-02-201501-03-2015500
201-01-201501-02-201580
201-02-201501-03-201570

What is a convenient way of achieving this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2025-02-01 04:52:03

您应该通过对group_by()进行分组,然后总结,例如

library(dplyr)    
df %>% 
      group_by(ID, start_time, End_time) %>% 
      summarise(Traffic = sum(Traffic))

You should achieve this by grouping group_by() and then summarize accordingly, e.g.

library(dplyr)    
df %>% 
      group_by(ID, start_time, End_time) %>% 
      summarise(Traffic = sum(Traffic))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文