如何过滤或子集R中的特定日期和时间间隔?露珠? [英] How to filter or subset specific date and time intervals in R? Lubridate?
问题描述
我需要做的是过滤或子集对应于课程计划的数据,以便我
课程安排与每个课程的时间不同,所以数据集/数据框的日期时间值和数值一周中的一天,例如周一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屋!