I'm sure it isn't hard to do but I cant find a way to sum up breeding time per hour. I have a couple thousands of event data (breeding) of birds that arrive on (AR) and leave from (LV) their nest. The corresponding times of arriving- and leaving-events are given in time and look like this:
times = as.POSIXct(c("2007-07-11 22:47:21 UTC", "2007-07-11 22:58:39 UTC", "2007-07-11 22:58:48 UTC", "2007-07-11 23:57:45 UTC", "2007-07-12 02:29:52 UTC", "2007-07-12 03:46:23 UTC", "2007-07-12 03:46:36 UTC", "2007-07-12 04:28:54 UTC", "2007-07-12 04:29:03 UTC", "2007-07-12 05:36:38 UTC"), tz = "UTC")
breeding = c("AR", "LV", "AR", "LV", "AR", "LV", "AR", "LV", "AR", "OFF")
Now I want to calculate what fraction per hour the birds spend on their nest, based on hourly breaks like these
cut(times, breaks = "hour")
only that the right end shall be included, too.
I tried summing up with difftime but then of course it didn't cut at the hour- and date- breaks. So the result should look like somehow this:
Hour fraction
22-23 12min
23-00 57min
00-01 0min
01-02 0min
02-03 31min
03-04 46min
04-05 1min
05-06 24min
Thanks already!!