juancda4
juancda4

Reputation: 333

Summing up time-stamped data into hourly intervals

I'm working with a large dataset and since I'm learning R, I would like to make it more manageable.

I've a series of 4 minute time-stamped intervals with respective measures of average distance travelled meters. Here's a sample of the data:

> head(datanet)
   Date & Time [Local]    meters
1:    19/06/2018 00:08  2.448087
2:    19/06/2018 00:12 58.595811
3:    19/06/2018 00:16 49.057392
4:    19/06/2018 00:20  1.716189
5:    19/06/2018 00:24  2.166232
6:    19/06/2018 00:28 33.752809

I simply would like to sum-up these 4 minute intervals into hourly intervals while calculating the average distance travelled for each hour of the day (from 0 to 23). I would like the output table to look like this:

> head(data_travel)
    hour avg_meters sd_meters
 1     0       7.32     12.5 
 2     1       6.58     11.3 
 3     2       7.66     17.0 
 4     3       6.13     14.0 
 5     4       4.26     10.2 
 6     5       3.84      7.54

To obtain data_travel, I used the following code:

data_travel<-datanet %>% 
  mutate(date = dmy_hm(`Date & Time [Local]`),
         hour = hour(date)) %>% 
  group_by(hour) %>%
  summarise(
    avg_meters = mean(meters),
    sd_meters = sd(meters))

However, this code makes an hourly average by calculating the average distance travelled datanet$meters for all 4 minute intervals included in each hour. As stated above, I was wondering how I could modify my code so that it will sum all 4 minute interval datanet$meters values into hourly intervals, and then making hourly averages for every single day in datanet.

Hope I was clear enough, but please feel welcome to ask for any other information. I will attach a dput(datanet) sample below for replicability:

> dput(datanet[1:600,])
structure(list(`Date & Time [Local]` = c("19/06/2018 00:08", 
"19/06/2018 00:12", "19/06/2018 00:16", "19/06/2018 00:20", "19/06/2018 00:24", 
"19/06/2018 00:28", "19/06/2018 00:32", "19/06/2018 00:36", "19/06/2018 00:40", 
"19/06/2018 00:44", "19/06/2018 00:48", "19/06/2018 00:52", "19/06/2018 00:56", 
"19/06/2018 01:00", "19/06/2018 01:04", "19/06/2018 01:08", "19/06/2018 01:12", 
"19/06/2018 01:16", "19/06/2018 01:20", "19/06/2018 01:24", "19/06/2018 01:28", 
"19/06/2018 01:32", "19/06/2018 01:36", "19/06/2018 01:40", "19/06/2018 01:44", 
"19/06/2018 01:48", "19/06/2018 01:52", "19/06/2018 01:56", "19/06/2018 02:00", 
"19/06/2018 02:04", "19/06/2018 02:08", "19/06/2018 02:12", "19/06/2018 02:16", 
"19/06/2018 02:20", "19/06/2018 02:24", "19/06/2018 02:28", "19/06/2018 02:32", 
"19/06/2018 02:36", "19/06/2018 02:40", "19/06/2018 02:44", "19/06/2018 02:48", 
"19/06/2018 02:52", "19/06/2018 02:56", "19/06/2018 03:00", "19/06/2018 03:04", 
"19/06/2018 03:08", "19/06/2018 03:12", "19/06/2018 03:16", "19/06/2018 03:20", 
"19/06/2018 03:24", "19/06/2018 03:28", "19/06/2018 03:32", "19/06/2018 03:36", 
"19/06/2018 03:40", "19/06/2018 03:44", "19/06/2018 03:48", "19/06/2018 03:52", 
"19/06/2018 03:56", "19/06/2018 04:00", "19/06/2018 04:04", "19/06/2018 04:08", 
"19/06/2018 04:12", "19/06/2018 04:16", "19/06/2018 04:20", "19/06/2018 04:24", 
"19/06/2018 04:28", "19/06/2018 04:32", "19/06/2018 04:36", "19/06/2018 04:40", 
"19/06/2018 04:44", "19/06/2018 04:48", "19/06/2018 04:52", "19/06/2018 04:56", 
"19/06/2018 05:00", "19/06/2018 05:04", "19/06/2018 05:08", "19/06/2018 05:12", 
"19/06/2018 05:16", "19/06/2018 05:20", "19/06/2018 05:24", "19/06/2018 05:28", 
"19/06/2018 05:32", "19/06/2018 05:36", "19/06/2018 05:40", "19/06/2018 05:44", 
"19/06/2018 05:48", "19/06/2018 05:52", "19/06/2018 05:56", "19/06/2018 06:00", 
"19/06/2018 06:04", "19/06/2018 06:08", "19/06/2018 06:12", "19/06/2018 06:16", 
"19/06/2018 06:20", "19/06/2018 06:24", "19/06/2018 06:28", "19/06/2018 06:32", 
"19/06/2018 06:36", "19/06/2018 06:40", "19/06/2018 06:44", "19/06/2018 06:48", 
"19/06/2018 06:52", "19/06/2018 06:56", "19/06/2018 07:00", "19/06/2018 07:04", 
"19/06/2018 07:08", "19/06/2018 07:12", "19/06/2018 07:16", "19/06/2018 07:20", 
"19/06/2018 07:24", "19/06/2018 07:28", "19/06/2018 07:32", "19/06/2018 07:36", 
"19/06/2018 07:40", "19/06/2018 07:44", "19/06/2018 07:48", "19/06/2018 07:52", 
"19/06/2018 07:56", "19/06/2018 08:00", "19/06/2018 08:04", "19/06/2018 08:08", 
"19/06/2018 08:12", "19/06/2018 08:16", "19/06/2018 08:20", "19/06/2018 08:24", 
"19/06/2018 08:28", "19/06/2018 08:32", "19/06/2018 08:36", "19/06/2018 08:40", 
"19/06/2018 08:44", "19/06/2018 08:48", "19/06/2018 08:52", "19/06/2018 08:56", 
"19/06/2018 09:00", "19/06/2018 09:04", "19/06/2018 09:08", "19/06/2018 09:12", 
"19/06/2018 09:16", "19/06/2018 09:20", "19/06/2018 09:24", "19/06/2018 09:28", 
"19/06/2018 09:32", "19/06/2018 09:36", "19/06/2018 09:40", "19/06/2018 09:44", 
"19/06/2018 09:48", "19/06/2018 09:52", "19/06/2018 09:56", "19/06/2018 10:00", 
"19/06/2018 10:04", "19/06/2018 10:08", "19/06/2018 10:12", "19/06/2018 10:16", 
"19/06/2018 10:20", "19/06/2018 10:24", "19/06/2018 10:28", "19/06/2018 10:32", 
"19/06/2018 10:36", "19/06/2018 10:40", "19/06/2018 10:44", "19/06/2018 10:48", 
"19/06/2018 10:52", "19/06/2018 10:56", "19/06/2018 11:00", "19/06/2018 11:04", 
"19/06/2018 11:08", "19/06/2018 11:12", "19/06/2018 11:16", "19/06/2018 11:21", 
"19/06/2018 11:24", "19/06/2018 11:28", "19/06/2018 11:32", "19/06/2018 11:36", 
"19/06/2018 11:40", "19/06/2018 11:44", "19/06/2018 11:48", "19/06/2018 11:52", 
"19/06/2018 11:56", "19/06/2018 12:00", "19/06/2018 12:04", "19/06/2018 12:08", 
"19/06/2018 12:12", "19/06/2018 12:16", "19/06/2018 12:20", "19/06/2018 12:24", 
"19/06/2018 12:28", "19/06/2018 12:32", "19/06/2018 12:36", "19/06/2018 12:40", 
"19/06/2018 12:44", "19/06/2018 12:48", "19/06/2018 12:52", "19/06/2018 12:56", 
"19/06/2018 13:00", "19/06/2018 13:04", "19/06/2018 13:08", "19/06/2018 13:12", 
"19/06/2018 13:16", "19/06/2018 13:20", "19/06/2018 13:24", "19/06/2018 13:28", 
"19/06/2018 13:32", "19/06/2018 13:36", "19/06/2018 13:40", "19/06/2018 13:44", 
"19/06/2018 13:48", "19/06/2018 13:52", "19/06/2018 13:56", "19/06/2018 14:00", 
"19/06/2018 14:04", "19/06/2018 14:08", "19/06/2018 14:12", "19/06/2018 14:16", 
"19/06/2018 14:20", "19/06/2018 14:24", "19/06/2018 14:28", "19/06/2018 14:32", 
"19/06/2018 14:36", "19/06/2018 14:40", "19/06/2018 14:44", "19/06/2018 14:48", 
"19/06/2018 14:52", "19/06/2018 14:56", "19/06/2018 15:00", "19/06/2018 15:04", 
"19/06/2018 15:08", "19/06/2018 15:12", "19/06/2018 15:16", "19/06/2018 15:20", 
"19/06/2018 15:24", "19/06/2018 15:28", "19/06/2018 15:32", "19/06/2018 15:36", 
"19/06/2018 15:40", "19/06/2018 15:44", "19/06/2018 15:48", "19/06/2018 15:52", 
"19/06/2018 15:56", "19/06/2018 16:00", "19/06/2018 16:04", "19/06/2018 16:08", 
"19/06/2018 16:12", "19/06/2018 16:16", "19/06/2018 16:20", "19/06/2018 16:24", 
"19/06/2018 16:28", "19/06/2018 16:32", "19/06/2018 16:36", "19/06/2018 16:40", 
"19/06/2018 16:44", "19/06/2018 16:48", "19/06/2018 16:52", "19/06/2018 16:56", 
"19/06/2018 17:00", "19/06/2018 17:04", "19/06/2018 17:08", "19/06/2018 17:12", 
"19/06/2018 17:16", "19/06/2018 17:20", "19/06/2018 17:24", "19/06/2018 17:28", 
"19/06/2018 17:32", "19/06/2018 17:36", "19/06/2018 17:40", "19/06/2018 17:44", 
"19/06/2018 17:48", "19/06/2018 17:52", "19/06/2018 17:56", "19/06/2018 18:00", 
"19/06/2018 18:04", "19/06/2018 18:08", "19/06/2018 18:12", "19/06/2018 18:16", 
"19/06/2018 18:20", "19/06/2018 18:24", "19/06/2018 18:28", "19/06/2018 18:32", 
"19/06/2018 18:36", "19/06/2018 18:40", "19/06/2018 18:44", "19/06/2018 18:48", 
"19/06/2018 18:52", "19/06/2018 18:56", "19/06/2018 19:00", "19/06/2018 19:04", 
"19/06/2018 19:08", "19/06/2018 19:12", "19/06/2018 19:16", "19/06/2018 19:20", 
"19/06/2018 19:24", "19/06/2018 19:28", "19/06/2018 19:32", "19/06/2018 19:36", 
"19/06/2018 19:40", "19/06/2018 19:44", "19/06/2018 19:48", "19/06/2018 19:52", 
"19/06/2018 19:56", "19/06/2018 20:00", "19/06/2018 20:04", "19/06/2018 20:08", 
"19/06/2018 20:12", "19/06/2018 20:16", "19/06/2018 20:20", "19/06/2018 20:24", 
"19/06/2018 20:28", "19/06/2018 20:32", "19/06/2018 20:36", "19/06/2018 20:40", 
"19/06/2018 20:44", "19/06/2018 20:48", "19/06/2018 20:52", "19/06/2018 20:56", 
"19/06/2018 21:00", "19/06/2018 21:04", "19/06/2018 21:08", "19/06/2018 21:12", 
"19/06/2018 21:16", "19/06/2018 21:20", "19/06/2018 21:24", "19/06/2018 21:28", 
"19/06/2018 21:32", "19/06/2018 21:36", "19/06/2018 21:40", "19/06/2018 21:44", 
"19/06/2018 21:48", "19/06/2018 21:52", "19/06/2018 21:56", "19/06/2018 22:00", 
"19/06/2018 22:04", "19/06/2018 22:08", "19/06/2018 22:12", "19/06/2018 22:16", 
"19/06/2018 22:20", "19/06/2018 22:24", "19/06/2018 22:28", "19/06/2018 22:32", 
"19/06/2018 22:36", "19/06/2018 22:40", "19/06/2018 22:44", "19/06/2018 22:48", 
"19/06/2018 22:52", "19/06/2018 22:56", "19/06/2018 23:00", "19/06/2018 23:04", 
"19/06/2018 23:08", "19/06/2018 23:12", "19/06/2018 23:16", "19/06/2018 23:20", 
"19/06/2018 23:24", "19/06/2018 23:28", "19/06/2018 23:32", "19/06/2018 23:36", 
"19/06/2018 23:40", "19/06/2018 23:44", "19/06/2018 23:48", "19/06/2018 23:52", 
"19/06/2018 23:56", "20/06/2018 00:00", "20/06/2018 00:04", "20/06/2018 00:08", 
"20/06/2018 00:12", "20/06/2018 00:16", "20/06/2018 00:20", "20/06/2018 00:24", 
"20/06/2018 00:28", "20/06/2018 00:32", "20/06/2018 00:36", "20/06/2018 00:40", 
"20/06/2018 00:44", "20/06/2018 00:48", "20/06/2018 00:52", "20/06/2018 00:56", 
"20/06/2018 01:00", "20/06/2018 01:04", "20/06/2018 01:08", "20/06/2018 01:12", 
"20/06/2018 01:16", "20/06/2018 01:20", "20/06/2018 01:24", "20/06/2018 01:28", 
"20/06/2018 01:32", "20/06/2018 01:36", "20/06/2018 01:40", "20/06/2018 01:44", 
"20/06/2018 01:48", "20/06/2018 01:52", "20/06/2018 01:56", "20/06/2018 02:00", 
"20/06/2018 02:04", "20/06/2018 02:08", "20/06/2018 02:12", "20/06/2018 02:16", 
"20/06/2018 02:20", "20/06/2018 02:24", "20/06/2018 02:28", "20/06/2018 02:32", 
"20/06/2018 02:36", "20/06/2018 02:40", "20/06/2018 02:44", "20/06/2018 02:48", 
"20/06/2018 02:52", "20/06/2018 02:56", "20/06/2018 03:00", "20/06/2018 03:04", 
"20/06/2018 03:08", "20/06/2018 03:12", "20/06/2018 03:16", "20/06/2018 03:20", 
"20/06/2018 03:24", "20/06/2018 03:28", "20/06/2018 03:32", "20/06/2018 03:36", 
"20/06/2018 03:40", "20/06/2018 03:44", "20/06/2018 03:48", "20/06/2018 03:52", 
"20/06/2018 03:56", "20/06/2018 04:00", "20/06/2018 04:04", "20/06/2018 04:08", 
"20/06/2018 04:12", "20/06/2018 04:16", "20/06/2018 04:20", "20/06/2018 04:24", 
"20/06/2018 04:28", "20/06/2018 04:32", "20/06/2018 04:36", "20/06/2018 04:40", 
"20/06/2018 04:44", "20/06/2018 04:48", "20/06/2018 04:52", "20/06/2018 04:56", 
"20/06/2018 05:00", "20/06/2018 05:04", "20/06/2018 05:08", "20/06/2018 05:12", 
"20/06/2018 05:16", "20/06/2018 05:20", "20/06/2018 05:24", "20/06/2018 05:28", 
"20/06/2018 05:32", "20/06/2018 05:36", "20/06/2018 05:40", "20/06/2018 05:44", 
"20/06/2018 05:48", "20/06/2018 05:52", "20/06/2018 05:56", "20/06/2018 06:00", 
"20/06/2018 06:04", "20/06/2018 06:08", "20/06/2018 06:12", "20/06/2018 06:16", 
"20/06/2018 06:20", "20/06/2018 06:24", "20/06/2018 06:28", "20/06/2018 06:32", 
"20/06/2018 06:36", "20/06/2018 06:40", "20/06/2018 06:44", "20/06/2018 06:48", 
"20/06/2018 06:52", "20/06/2018 06:56", "20/06/2018 07:00", "20/06/2018 07:04", 
"20/06/2018 07:08", "20/06/2018 07:12", "20/06/2018 07:16", "20/06/2018 07:20", 
"20/06/2018 07:24", "20/06/2018 07:28", "20/06/2018 07:32", "20/06/2018 07:36", 
"20/06/2018 07:40", "20/06/2018 07:44", "20/06/2018 07:48", "20/06/2018 07:52", 
"20/06/2018 07:56", "20/06/2018 08:00", "20/06/2018 08:04", "20/06/2018 08:08", 
"20/06/2018 08:12", "20/06/2018 08:16", "20/06/2018 08:20", "20/06/2018 08:24", 
"20/06/2018 08:28", "20/06/2018 08:32", "20/06/2018 08:36", "20/06/2018 08:40", 
"20/06/2018 08:44", "20/06/2018 08:48", "20/06/2018 08:52", "20/06/2018 08:56", 
"20/06/2018 09:00", "20/06/2018 09:04", "20/06/2018 09:08", "20/06/2018 09:12", 
"20/06/2018 09:16", "20/06/2018 09:20", "20/06/2018 09:24", "20/06/2018 09:28", 
"20/06/2018 09:32", "20/06/2018 09:36", "20/06/2018 09:40", "20/06/2018 09:44", 
"20/06/2018 09:48", "20/06/2018 09:52", "20/06/2018 09:56", "20/06/2018 10:00", 
"20/06/2018 10:04", "20/06/2018 10:08", "20/06/2018 10:12", "20/06/2018 10:16", 
"20/06/2018 10:20", "20/06/2018 10:24", "20/06/2018 10:28", "20/06/2018 10:32", 
"20/06/2018 10:36", "20/06/2018 10:40", "20/06/2018 10:44", "20/06/2018 10:48", 
"20/06/2018 10:52", "20/06/2018 10:56", "20/06/2018 11:00", "20/06/2018 11:04", 
"20/06/2018 11:08", "20/06/2018 11:12", "20/06/2018 11:16", "20/06/2018 11:20", 
"20/06/2018 11:24", "20/06/2018 11:28", "20/06/2018 11:32", "20/06/2018 11:36", 
"20/06/2018 11:40", "20/06/2018 11:44", "20/06/2018 11:48", "20/06/2018 11:52", 
"20/06/2018 11:56", "20/06/2018 12:00", "20/06/2018 12:04", "20/06/2018 12:08", 
"20/06/2018 12:12", "20/06/2018 12:16", "20/06/2018 12:20", "20/06/2018 12:24", 
"20/06/2018 12:28", "20/06/2018 12:32", "20/06/2018 12:36", "20/06/2018 12:40", 
"20/06/2018 12:44", "20/06/2018 12:48", "20/06/2018 12:52", "20/06/2018 12:56", 
"20/06/2018 13:00", "20/06/2018 13:04", "20/06/2018 13:08", "20/06/2018 13:12", 
"20/06/2018 13:16", "20/06/2018 13:20", "20/06/2018 13:24", "20/06/2018 13:28", 
"20/06/2018 13:32", "20/06/2018 13:36", "20/06/2018 13:40", "20/06/2018 13:44", 
"20/06/2018 13:48", "20/06/2018 13:52", "20/06/2018 13:56", "20/06/2018 14:00", 
"20/06/2018 14:04", "20/06/2018 14:08", "20/06/2018 14:12", "20/06/2018 14:16", 
"20/06/2018 14:20", "20/06/2018 14:24", "20/06/2018 14:28", "20/06/2018 14:32", 
"20/06/2018 14:36", "20/06/2018 14:40", "20/06/2018 14:44", "20/06/2018 14:48", 
"20/06/2018 14:52", "20/06/2018 14:56", "20/06/2018 15:00", "20/06/2018 15:04", 
"20/06/2018 15:08", "20/06/2018 15:12", "20/06/2018 15:16", "20/06/2018 15:20", 
"20/06/2018 15:24", "20/06/2018 15:28", "20/06/2018 15:32", "20/06/2018 15:36", 
"20/06/2018 15:40", "20/06/2018 15:44", "20/06/2018 15:48", "20/06/2018 15:52", 
"20/06/2018 15:56", "20/06/2018 16:00", "20/06/2018 16:04"), 
    meters = c(2.44808743796531, 58.5958105549192, 49.0573915168004, 
    1.71618923544311, 2.16623234264144, 33.7528092143734, 1.26876292628825, 
    4.09301793236524, 6.47380341213986, 2.02287444044928, 6.15764791418056, 
    4.88198337685391, 6.1518534564327, 19.9293981357374, 31.2807443706163, 
    11.9760177553429, 7.80034538189425, 2.09856685581426, 15.5559610933875, 
    5.54425190776513, 4.31727752887657, 1.69695203818687, 3.13701726469391, 
    4.17079079435503, 0, 0.253518261190509, 0.768515387271088, 
    5.75312128614323, 1.10161787301914, 0, 1.63627263077218, 
    1.94331762790558, 0.984128914771002, 0, 1.891376142142, 1.88169045315321, 
    1.14968339087591, 1.94662436122789, 2.53667294419711, 2.22463784687921, 
    1.14716037069784, 1.72269599615416, 0.253518262766866, 0.557086177521366, 
    0.834805798848609, 0.834805798848609, 0.834805798848609, 
    0.32373515360376, 0.250851604274291, 1.13037794205011, 1.01730179938836, 
    1.08245009766703, 1.29008139493895, 0.592050658495912, 0.984128914593752, 
    1.14716037069784, 0.246921421310107, 1.08086752437222, 0, 
    0.253518261190127, 0.834146432905571, 0.834146432905571, 
    1.32088856328962, 0, 1.01730179951988, 0.557086174016414, 
    0, 0, 0.981930302577223, 1.01730179952143, 0.801467385970428, 
    1.891376142142, 0.984128914771002, 0.984128914771002, 1.891376142142, 
    1.31556194378487, 1.70331684297699, 11.4746462151774, 5.19876037652309, 
    18.1991232643532, 5.45048803468078, 3.50474735760544, 0.834439563061093, 
    0, 1.29008140210492, 0.984760642562075, 1.01730179907391, 
    32.657190675824, 39.7593130805261, 34.2547425122791, 12.1116764053771, 
    18.526009117261, 3.86538989203226, 7.07005984938157, 1.72929805654892, 
    6.73320732100181, 23.0796824899771, 66.8539968083065, 101.031538229766, 
    142.563193250685, 117.93396678646, 30.4231296530894, 43.3196594211314, 
    14.3288406144688, 6.01740959634099, 7.35496556381327, 7.0780957149326, 
    1.06782836828317, 10.3553242863905, 59.205976673877, 34.5440414717095, 
    90.5195981896788, 32.8711449150829, 3.40710213072646, 6.60140695190154, 
    20.751091499863, 1.89137226358219, 2.83321448749677, 26.5437774761593, 
    4.78947844059108, 15.9299548924479, 3.49392462916022, 0.834803361386949, 
    53.9702480435499, 44.7123678229481, 4.58801253896994, 9.09964716760873, 
    52.4316347054904, 83.5342865610675, 4.66725660885041, 12.5978430947004, 
    1.94751698101872, 0.504253850871525, 3.45174941271515, 1.63626628055968, 
    5.40488600424627, 12.3995886978579, 16.9313577940681, 3.91617610821253, 
    4.70252672649754, 17.2466244205231, 5.87640930205112, 7.83322335835387, 
    68.1235163864855, 3.42589865816882, 13.1957354034354, 11.2205841718684, 
    1.01730188003348, 2.08209678645147, 2.82727432802774, 32.5321887823726, 
    12.067922456633, 1.8035643067272, 1.2090985158482, 2.5520360706561, 
    3.727677427748, 18.1658365688268, 2.53389262037358, 4.5038564350202, 
    3.99153396380181, 26.3513692155869, 52.630041380923, 53.0536675276293, 
    43.8202570822247, 17.9563768133082, 35.8843410313514, 2.52741128965252, 
    2.07122243755901, 61.1369106676384, 31.0602902769797, 1.93735691953792, 
    1.39063392798036, 4.74080462885894, 1.83677904498507, 1.5837058884799, 
    24.8779450701876, 1.02751235639547, 5.21277171962475, 5.88014964276792, 
    7.13082208780676, 1.84782941870358, 4.28412823329233, 4.8726754921709, 
    1.80492747976475, 0.834142917601792, 12.8071661996776, 45.7714211143098, 
    14.9358063376832, 117.774596740257, 1.94331089207628, 2.89950585430524, 
    1.55188895271854, 1.97146416004927, 3.62849282585251, 0.682586430353306, 
    1.14715895538192, 84.973523683883, 16.6260802285038, 5.17522902371143, 
    2.99113461676237, 7.1948737543452, 2.71109872104149, 4.22696799241781, 
    4.53907546305565, 5.71728738868701, 8.68379208483034, 3.75585732758793, 
    4.82085426327032, 5.81439758874005, 3.39028745288001, 3.55051027017038, 
    60.2330430998918, 38.3544603220122, 1.21375339001644, 1.91785016319426, 
    0.3237336743715, 1.69694647561642, 1.14877752688831, 2.37357312547656, 
    0, 0.909047979716786, 1.08244477955533, 3.35946823082954, 
    2.16622390570235, 1.9688553226609, 1.13578000777225, 1.63525542752795, 
    1.48883000783912, 2.83467921372661, 2.12754007740878, 17.3540112473834, 
    6.32166165556282, 1.94746224312546, 14.5084951818398, 3.71993035536828, 
    3.82335882963004, 2.84750706444208, 0, 1.71618366510756, 
    0.323733628303048, 6.97407775313294, 27.9890313303321, 2.18646977811563, 
    2.96545099539278, 0, 2.00143091430776, 14.0439085683219, 
    0.25351711418234, 1.69380290439435, 2.28323132482563, 3.85986892850026, 
    2.69197208488191, 2.22437966566857, 9.49208589978412, 49.4880243971914, 
    100.881212266528, 5.84222371086618, 85.6548691469987, 0.834143439442611, 
    71.1685884754485, 10.0799187801841, 37.4349094205841, 3.96457080819355, 
    8.02426971700344, 2.64427066449314, 11.2298595430791, 19.152210952781, 
    25.9621194522378, 2.43632829382703, 6.05555098063067, 154.726395809777, 
    18.7647119416837, 27.2616358671239, 11.5922993940012, 68.2775157158671, 
    49.1853059189567, 35.5259047498724, 28.1895151756555, 11.2830643554028, 
    70.5225858134716, 33.761787160485, 9.92505257193424, 12.2487708385319, 
    4.72780789239903, 2.36949301171681, 0.898029677765623, 1.41928645304406, 
    1.98000060537725, 7.46921332355175, 2.93628219004468, 3.6470392684573, 
    1.10014488207181, 4.92479363929599, 14.8930755174664, 5.83901213703915, 
    1.72269354554739, 7.485351543375, 5.3630772018188, 14.5613108033135, 
    6.95128356614464, 2.84031328921816, 8.22896775502526, 0.990766534590514, 
    6.06503541796136, 15.9514929128702, 13.8886767897834, 13.6568135914468, 
    4.37835160159707, 17.4136820914597, 10.9348080118824, 5.78925441619791, 
    1.96886057231489, 3.1381105751168, 3.00555214539433, 8.65031990810392, 
    18.0889311952119, 4.9279620177745, 6.53967791518033, 5.12248780673471, 
    9.65327444852992, 2.90279381701306, 3.25053402550702, 0.178554668218116, 
    2.11296628947042, 0, 2.05463008665439, 3.28780487743892, 
    3.27975197232669, 1.11688313023969, 3.54263761112745, 3.44538669236583, 
    3.26397986165939, 2.09856659919216, 5.37139341320134, 5.6924115655593, 
    4.60202445590286, 5.63519686389923, 0.164491876481961, 5.58649708275454, 
    1.99037317817474, 2.09856661192938, 0.323734465222267, 10.9597411401486, 
    0.355947189782921, 3.41945361430353, 0.834803831078743, 0.250851041368678, 
    1.71618672360682, 2.2852443811266, 2.75621241080264, 0.26426805222581, 
    2.51667455252664, 1.00624421937038, 1.31556073170562, 1.74973103655628, 
    2.85470073986884, 2.23598107180386, 4.39924042713072, 1.13637486281635, 
    1.89137280623378, 1.7226933586247, 2.78048150152117, 2.34179749193013, 
    1.25316474794988, 2.21959335815215, 0.508244295773855, 3.74975153237017, 
    13.149671771889, 3.11665920620628, 6.23793957023023, 5.76389033788265, 
    3.87181482346228, 17.2539366581823, 13.9629566469506, 1.18948102244285, 
    0.842132269722475, 2.3079403629024, 3.22202261290361, 2.36940127670928, 
    1.10161718027094, 1.23036012870167, 1.44528080857393, 4.33912713501579, 
    3.37568114504235, 92.5061970159523, 15.1473029005529, 1.34329004795447, 
    15.3378172470626, 38.6787490995308, 10.4150628574798, 5.16090629616039, 
    3.88900480774884, 22.6141938753557, 6.77356179715116, 4.98970146954142, 
    4.4476292646394, 6.26906224797557, 1.39023940162278, 7.42145857432984, 
    6.37076894177711, 3.20787547860737, 6.09669717817442, 12.7172285018803, 
    0.949839648692555, 1.46786489170902, 4.03188339764125, 3.91757759306007, 
    3.95734940246301, 2.53774861466072, 2.42258275920004, 1.2687612155428, 
    4.45830333030312, 2.60279939002241, 1.75804360203232, 2.69011657922181, 
    1.11875056679867, 1.31291355558492, 3.72294257511327, 5.85904402983352, 
    3.20832775534171, 2.94305935624604, 1.11883078392019, 5.35780500511764, 
    4.75737751836462, 3.7797126497569, 3.7983876336386, 0.992642808455696, 
    1.95049316835008, 0.326928736110427, 2.11296628522846, 4.07169801967702, 
    2.52646668531718, 3.98439222182978, 17.3497682831101, 7.29287133428605, 
    5.07198922518777, 7.94327223877522, 4.21936216010894, 4.17085013299816, 
    3.51685167026273, 12.1052177107224, 3.58791865589084, 0.345184970911049, 
    25.4334245257739, 5.80573580422777, 35.000868536876, 8.10375006720313, 
    5.55281888651586, 54.122801176503, 78.6122060214781, 41.3856781743243, 
    29.3869654366895, 17.7290898521386, 5.0727936105876, 8.69175045974807, 
    18.1432543449944, 12.8803776272175, 29.2426091559512, 24.0410724264769, 
    6.4730699858908, 4.97778488612594, 7.98974707421611, 20.2030086451785, 
    22.1004399878353, 7.03390237116815, 45.7551255401772, 15.7996996015042, 
    7.12481688064979, 15.14973228876, 14.6076640793528, 15.1550709759375, 
    58.8730245824517, 26.5873725074242, 12.5870303497807, 5.03716730380475, 
    38.1705581255245, 4.98970798696197, 10.1776179729454, 25.217055842654, 
    11.9516788780249, 12.669062749606, 7.73978160189179, 3.37228542529022, 
    0, 3.71423685874906, 2.85364856346313, 3.44414752567999, 
    2.90543442635672, 8.98576916502848, 1.92476560963452, 41.4656975480745, 
    57.0989390844393, 22.3744887923602, 2.96841168956654, 26.2453314146389, 
    6.9174612502291, 2.78067958921905, 27.3550989792586, 3.15962129421371, 
    28.0266554781833, 9.20725178349371, 9.00090987042938, 8.58660729823275, 
    7.30908738520302, 8.10592814175095, 6.36483938524261, 16.2895500070345, 
    18.1241335683301, 50.5669273617538, 11.0156880820439, 5.01288978842153, 
    5.20133717413646, 15.2472532565554, 54.7082370940267, 0.543048851100661, 
    13.0704393172337, 2.04397356306332, 28.0184862392233, 10.8145040763618, 
    5.18989706519256, 30.9569333188036, 17.0758188538247, 12.9639136418556, 
    4.21553374158597, 2.21867363557909, 3.20060551545172, 2.3542294284986, 
    3.52659914316559, 2.81079400365034, 2.63407409416559, 15.2542773090476, 
    5.83454590225097, 10.3667133861544, 10.9691677632064, 15.0533816932101, 
    13.3184444885844, 8.88034267698768, 8.95506509766773, 10.6053243989646, 
    1.47480465490458, 11.9007158977125, 4.0163011217278, 2.24874580705771, 
    1.14747782393574, 0, 4.11576916836101, 3.11605492423595, 
    8.09047648545038, 2.18074010384694, 1.71618654313603, 1.20921021376415, 
    1.35730915904455, 1.02468095685514, 1.84014652106038, 1.96559787725097, 
    7.22538854125882, 110.710506104258, 14.1142134710612, 4.83754559107978, 
    24.2811765275612, 13.0013801006934, 2.18125902188903, 3.52698875031459, 
    45.6847738271103, 53.8283683285118, 14.8075122731054, 28.1771092358655, 
    8.32706839259918, 26.5270863431792, 18.1611283239827, 10.7755401365176, 
    5.9673899532775, 1.13788092724148, 1.52128827048372, 0.958976970260541, 
    69.2121958577161, 30.5351336420922, 38.667539515082, 40.2519045922232, 
    2.16644127107185, 19.1062531922013, 3.11651754962896, 4.78193603065187, 
    47.6776803218739, 2.97550160218521, 1.13749423128259, 3.61040062413504, 
    21.1348702782536, 8.3605926367108, 9.09671439800553, 2.38935030580104, 
    1.84014937285323, 3.28335763479908, 7.43577096342995, 7.23525643890005, 
    4.61555647347363, 7.94238654545671, 14.970359736519, 7.95431068709035, 
    6.02282527514472)), row.names = c(NA, -600L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x0000000002641ef0>)

Upvotes: 0

Views: 61

Answers (1)

Jon Spring
Jon Spring

Reputation: 66900

I think you need to first collect all the hour totals from each day, then average those across days. This can be done by grouping by both day and hour. The first time you summarise, it will get the total for each day-hour combination, and leave the data grouped by hour, so that you can compare all the hour 1's against other hour 1's. The second summarise will then create the averages and SD of those hour totals across days.

data_travel <- datanet %>% 
  mutate(date = dmy_hm(`Date & Time [Local]`),
         day  = as_date(date),
         hour = hour(date)) %>% 
  group_by(hour, day) %>%
  summarise(hr_meters = sum(meters)) %>%
  summarise(avg_meters = mean(hr_meters),
            sd_meters  = sd(hr_meters))

Upvotes: 1

Related Questions