如何过滤或子集R中的特定日期和时间间隔?露珠? [英] How to filter or subset specific date and time intervals in R? Lubridate?

查看:153
本文介绍了如何过滤或子集R中的特定日期和时间间隔?露珠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由两列组成的数据集。 datetime列和带数值的列。它是一个简单的数据集,所以我没有附加它。



我需要做的是过滤或子集对应于课程计划的数据,以便我



课程安排与每个课程的时间不同,所以数据集/数据框的日期时间值和数值一周中的一天,例如周一8:00-9.50,10.30-11.30,14.50-15:50。星期二10.30-11.30,14.10-15.30,星期三...等等。



任何想法我该怎么做?



我通常将datetime-values转换为POSIXct格式,但是最近我读到了关于lubridate。



我仍然不知道如何有效地子集所有这些标准。



也许我应该首先按照工作日对数据进行子集。
然后根据演讲时间分组不同的工作日...



希望有人可以帮助我。



BTW:数据是2014年的全部,所以我实际上必须避免数据,当课程有假期时,...

解决方案

将课间隔转换为间隔 class lubridate 。然后基于测试的子集,如果日期是在间隔中...

 >一个<  -  new_interval(Sys.time(),Sys.time()+ 120)
> Sys.time()%%a
[1] TRUE


I have a dataset consisting of two columns. A datetime column and a column with numerical values. Its a simple dataset, so I did not attach it..

What I need to do, is to filter or subset the data corresponding with a class schedule, so that I get a dataset/dataframe with datetime values and numerical values for the time when the class has lectures only.

The class schedule is different from each day of the week, e.g. Mondays 8:00-9.50, 10.30-11.30, 14.50-15:50. Tuesdays 10.30-11.30, 14.10-15.30, Wednesdays...an so on.

Any idea how I could do this?

I usually convert datetime-values to POSIXct format, but recently I read about lubridate.

I am just still not sure how to efficiently subset with all these criteria.

Perhaps I should subset the data according to the weekdays first. And then subset the different weekdays according to the lecture time...

Hope someone can help me.

BTW: The data is for all of 2014, so I actually have to avoid the data when the class have holidays as well...

解决方案

Convert class intervals to an interval class in lubridate. Then subset based on the test of if the dates are in the intervals...

> a <- new_interval(Sys.time(), Sys.time() + 120)
> Sys.time() %within% a
[1] TRUE

这篇关于如何过滤或子集R中的特定日期和时间间隔?露珠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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