Reputation: 9018
I have this list of dates for different days:
data = as.POSIXct(c("2017-01-03 06:14:08","2017-01-03 06:15:08","2017-01-03 06:33:07","2017-01-03 06:57:57",
"2017-01-03 07:01:08","2017-01-03 07:15:08","2017-01-03 07:33:08","2017-01-03 08:29:08","2017-01-03 08:34:08"),tz = "GMT")
I'd like to create a column that bins the dates into 1 hour buckets starting at 30th minute of the hour so the result would be in the "BUCKET" column below
as.data.frame(data)
data BUCKET
1 2017-01-03 06:14:08 530
2 2017-01-03 06:15:08 530
3 2017-01-03 06:33:07 630
4 2017-01-03 06:57:57 630
5 2017-01-03 07:01:08 630
6 2017-01-04 07:15:08 630
7 2017-01-04 07:33:08 730
8 2017-01-05 08:29:08 730
9 2017-01-05 08:34:08 830
Upvotes: 0
Views: 59
Reputation: 18435
Here is one way to do it...
bucket <- paste0(as.numeric(format(data-60*30,format("%H"))),"30")
bucket
[1] "530" "530" "630" "630" "630" "630" "730" "730" "830"
Upvotes: 2