Fairways_and_Greens
Fairways_and_Greens

Reputation: 53

Can I use lubridate to get a number of instances within intervals using %within%?

I'm trying to create a visualization that shows for some predecessor/successor operations, how many employees are clocked in through a 24 hour clock.

I created a vector of instances two hours a part from each other. I converted a table of labor records (clock-in and clock-out) to a data.frame of intervals. When I use the %within% function I only get the T/F back for the first instance of my vector.

graph.instants <- seq( ymd("2014-05-12"), by= "2 hours", len= 120) #Make vector of instants in 2 hour intervals
ln205intervals <- data.frame(ints = interval(Frame206$LaborOn, Frame206$LaborOff)) #Make intervals with LN205 data

graph.instants %within% ln205intervals$ints

Is there a way to check a vector of instants against a vector of intervals?

Here is a picture of my problem:

enter image description here

Upvotes: 4

Views: 181

Answers (1)

ckluss
ckluss

Reputation: 1271

for the archive as an alternative: dplyr defines a between

library(lubridate)
library(dplyr)

dat <- data.frame(time = seq( ymd("2015-01-01"), by= "2 hours", len= 1000))  

dat %>%  filter(between(time, ymd("2015-01-10"), ymd("2015-01-11")))

Upvotes: 1

Related Questions