Two closely related posts are here and here. I haven't been able to translate either of these to my exact situation.
Here is a vector of times:
start.time = as.POSIXct("2013-06-20 01:00:00")
x = start.time + runif(5, min = 0, max = 8*60)
x = x[order(x)]
x
# [1] "2013-06-20 01:00:30 EDT" "2013-06-20 01:00:57 EDT"
# [3] "2013-06-20 01:01:43 EDT" "2013-06-20 01:04:01 EDT"
# [5] "2013-06-20 01:04:10 EDT"
Next, here is a vector of two-minute markers:
y = seq(as.POSIXct("2013-06-20 01:00:00"), as.POSIXct("2013-06-20 01:06:00"), 60*2)
y
# [1] "2013-06-20 01:00:00 EDT" "2013-06-20 01:02:00 EDT"
# [3] "2013-06-20 01:04:00 EDT" "2013-06-20 01:06:00 EDT"
I would like a quick, slick, scalable way to produce the counts of the elements of x
that fall in to the two-minute bins to the right of each element of y
, like this:
y count.x
1 2013-06-20 01:00:00 3
2 2013-06-20 01:02:00 0
3 2013-06-20 01:04:00 2
4 2013-06-20 01:06:00 0