匹配时间在开始和结束时间之间的时间间隔 [英] matching time a time in the interval between a start and end time

查看:273
本文介绍了匹配时间在开始和结束时间之间的时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

StackOverflow的同事R用户 -



我必须将一组不同的时间与另一个数据帧中的开始和结束时间间隔进行匹配。这将导致一个具有多对一关系的数据框架。



一组简化的记录匹配如下:

  vid开始结束
17599 7588 2011-02-14 19:00:00 2011-02-14 19:11:00
17601 7588 2011 -02-14 19:58:00 2011-02-14 20:43:00
17603 7588 2011-02-14 21:22:00 2011-02-14 22:00:00

与上述数据匹配的一些示例记录为:

  vid datetime 
469818 7588 2011-02-14 19:00:10
470747 7588 2011-02-14 19:59:10
470788 7588 2011-02-14 21:23:10

我想要的是:

  vid datetime start end 
7588 2011-02-14 19:00:10 2011-02-14 19:00:00 2011-02-14 19:11:00
7588 2011-02-14 19:59:10 2011-02-14 19:58:00 2011-02-14 20:43:00
7588 2011-02-14 21:23:10 2011-02-14 21:22:00 2011-02-14 22:00:00


$ b $对于我的生活,我不知道如何在R中做任何帮助将不胜感激。谢谢!

解决方案

我做了,但是解决问题,使用> =和< =运算符比较开始,结束和datetime字段,在使用split()分割数据之后。 ; match.col = with(d2 [[v]],d1 $ datetime> = d2.start& d1 $ datetime< = d2.end) p>

Fellow R users of StackOverflow-

I have to match a set of distinct times to intervals of time defined in another data frame by a start and end. This would result in one data frame with a many to one relation.

A simplified set of the records to match into follows:

       vid               start                 end
17599 7588 2011-02-14 19:00:00 2011-02-14 19:11:00
17601 7588 2011-02-14 19:58:00 2011-02-14 20:43:00
17603 7588 2011-02-14 21:22:00 2011-02-14 22:00:00

And some example records to match to the above data are:

        vid            datetime
469818 7588 2011-02-14 19:00:10
470747 7588 2011-02-14 19:59:10
470788 7588 2011-02-14 21:23:10

What I would like is something like:

        vid            datetime               start                 end
        7588 2011-02-14 19:00:10 2011-02-14 19:00:00 2011-02-14 19:11:00
        7588 2011-02-14 19:59:10 2011-02-14 19:58:00 2011-02-14 20:43:00
        7588 2011-02-14 21:23:10 2011-02-14 21:22:00 2011-02-14 22:00:00

For the life of me, I can't figure out how to do this in R. Any help would be greatly appreciated. Thank you!

解决方案

I did, however solve the problem, using >= and <= operators to compare the start, end and datetime fields, after splitting the data using split(). ;match.col = with(d2[[v]], d1$datetime >= d2.start & d1$datetime <= d2.end)

这篇关于匹配时间在开始和结束时间之间的时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆