Aggregating minutes data to hour

Hello there,
I have a dataset looking like that mentions below
elecdemand

I want to transform the minute's data to hourly data by adding the values having the same hour on their time index. In one word, I need to group them according to an hour. I have tried several aggregate functions but can't find the desired value. Some of them are giving only integer values and some of them are giving wrong. How can I get the aggregate value according to an hour from here?

Thanks in advance.

**I am in the learning phase of R programming

Hi, you can use lubridate and do something like this:
Aggregation of 15-min to hourly for each day-month-year - tidyverse - RStudio Community

Also, next time please post your code and a reproducible example (not a screenshot).

1 Like
library(tidyverse)
library(lubridate)

tibble(
  timestamp = now() - dminutes(sample(1:1440, 100))) |>
  mutate(hour = floor_date(timestamp, "hours")) |>
  count(hour)
#> # A tibble: 24 × 2
#>    hour                    n
#>    <dttm>              <int>
#>  1 2022-09-28 09:00:00     3
#>  2 2022-09-28 10:00:00     6
#>  3 2022-09-28 11:00:00     2
#>  4 2022-09-28 12:00:00     3
#>  5 2022-09-28 13:00:00     8
#>  6 2022-09-28 14:00:00     1
#>  7 2022-09-28 15:00:00     2
#>  8 2022-09-28 16:00:00     9
#>  9 2022-09-28 17:00:00     3
#> 10 2022-09-28 18:00:00     6
#> # … with 14 more rows

Created on 2022-09-29 with reprex v2.0.2

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.