如何进行循环以将所有行与r中的时间公差匹配?
两个数据库DT1和DT2:
DT1
DATE | SERVICE_ID | ROUTE_ID | ID_ID ID_COURSE | stop_name | Dewtrure_time |
---|---|---|---|---|---|
2021-04-06 | - | 93 | 1 | MONET | 05:14:00 |
1899-12-31 | 1-31 | TCAR_R | 我有 | Théâtredes Arts | 08:44:00 |
2021-04-09 | TCAR_R- | 33 | HAMEAU | defrévaux1899-12-31 | 12:45:00 |
2021-04-04-04-04 | 1-31 | 25 | 1899-12-31 | HôtelDeVille | 16:21:00 |
2021-04-06 | 1-31 | 120 | 348 | de | 08:05:00 |
1899-12-31
- | l' | RUE | 1899-12-31 | TCAR_R | Eglise |
---|---|---|---|---|---|
-06 | TCAR_R-1-31 | 93 | 4960 | 莫奈 | 1899-12-31 05:14:00 |
2021-04-08 | TCAR_R-1-31 | 212103THéâtreArts | Arts | Arts Arts Arts | 1899-12-31 |
08:39:00 | TCAR_R-1-31 | 13 | 1211Hôtelde | Ville | 1899-12-31 16:19:00 |
TCAR_R_R | -1-31 | 25 | 2334 | HAMEAU | deFRévaux18999999999-12-31 12:47:00 |
2021-04-09 | TCAR_R-1-31 | 120 | 14542 | RUE de l'Eglise | 1899-12-31 07:59:00 |
我想将DT1的线与DT2的线与以下公差匹配:
**确切的公差日期,stop_name,service_id and service_id and and service_id and and service_id and and service_id and and service_id and and service_id and and service_id and and和route_id
** Random tolerance on Departure_time: ie tolerance interval must change "n" times until all rows in DT1 match in DT2
the desired output is:
Date | service_id | route_id | id_course | stop_name | Departure_timeDT1 | trip_id | Departure_timeDT2 |
---|---|---|---|---|---|---|---|
2021-04-06 | TCAR_R-1-31 | 93 | 1 | 莫奈 | 1899-12-31 05:14:00 | 4960 | 1899-12-31 05:14:00 |
2021-04-07 | TCAR_R-1-31 | 21 | 512 | ARTS ARTS ARTS | 189999-12-31 08:44:00 | THETE | ARTS 12-31 08:39:00 |
2021-04-09 | -1-31 | 25 | 33 | HAMEAU | defrévaux1899-12-31 12:45:00 | 2334 | 12:47:00 |
1899-12-31 | TCAR_R -1-31 | 13 | 2HôtelDeVille | 1899-12-31 | 16:21:00 | 1211 | 1899-12-31 16:19:00 |
2021-04-06 | TCAR_R-1-31 | 120 | 348 | RUE DE L'EGLISE | 1899-12 -31 08:05:00 | 14542 | 1899-12-31 07:59:00 |
我想在R中使用一个循环进行此操作,因为我的两个数据库很大,我真的很感谢任何帮助!
I have two databases DT1 and DT2:
DT1
Date | service_id | route_id | id_course | stop_name | Departure_time |
---|---|---|---|---|---|
2021-04-06 | TCAR_R-1-31 | 93 | 1 | Monet | 1899-12-31 05:14:00 |
2021-04-08 | TCAR_R-1-31 | 21 | 512 | Théâtre des Arts | 1899-12-31 08:44:00 |
2021-04-09 | TCAR_R-1-31 | 25 | 33 | Hameau de Frévaux | 1899-12-31 12:45:00 |
2021-04-09 | TCAR_R-1-31 | 13 | 2 | Hôtel de Ville | 1899-12-31 16:21:00 |
2021-04-06 | TCAR_R-1-31 | 120 | 348 | Rue de l'Eglise | 1899-12-31 08:05:00 |
DT2
Date | service_id | route_id | trip_id | stop_name | Departure_time |
---|---|---|---|---|---|
2021-04-06 | TCAR_R-1-31 | 93 | 4960 | Monet | 1899-12-31 05:14:00 |
2021-04-08 | TCAR_R-1-31 | 21 | 21203 | Théâtre des Arts | 1899-12-31 08:39:00 |
2021-04-09 | TCAR_R-1-31 | 13 | 1211 | Hôtel de Ville | 1899-12-31 16:19:00 |
2021-04-09 | TCAR_R-1-31 | 25 | 2334 | Hameau de Frévaux | 1899-12-31 12:47:00 |
2021-04-06 | TCAR_R-1-31 | 120 | 14542 | Rue de l'Eglise | 1899-12-31 07:59:00 |
I want to match the lines of DT1 with those of DT2 with the following tolerances:
** Exact tolerance on Date, stop_name, service_id and route_id
** Random tolerance on Departure_time: i.e. tolerance interval must change "n" times until all rows in DT1 match in DT2
the desired output is:
Date | service_id | route_id | id_course | stop_name | Departure_timeDT1 | trip_id | Departure_timeDT2 |
---|---|---|---|---|---|---|---|
2021-04-06 | TCAR_R-1-31 | 93 | 1 | Monet | 1899-12-31 05:14:00 | 4960 | 1899-12-31 05:14:00 |
2021-04-07 | TCAR_R-1-31 | 21 | 512 | Théâtre des Arts | 1899-12-31 08:44:00 | 21203 | 1899-12-31 08:39:00 |
2021-04-09 | TCAR_R-1-31 | 25 | 33 | Hameau de Frévaux | 1899-12-31 12:45:00 | 2334 | 1899-12-31 12:47:00 |
2021-04-09 | TCAR_R-1-31 | 13 | 2 | Hôtel de Ville | 1899-12-31 16:21:00 | 1211 | 1899-12-31 16:19:00 |
2021-04-06 | TCAR_R-1-31 | 120 | 348 | Rue de l'Eglise | 1899-12-31 08:05:00 | 14542 | 1899-12-31 07:59:00 |
I want to do this with a loop in R because my two databases are very large, I will be really grateful for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论