Hello there,
I have a dataset looking like that mentions below
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).
A minimal reproducible example consists of the following items:
A minimal dataset, necessary to reproduce the issue
The minimal runnable code necessary to reproduce the issue, which can be run
on the given dataset, and including the necessary information on the used packages.
Let's quickly go over each one of these with examples:
Minimal Dataset (Sample Data)
You need to provide a data frame that is small enough to be (reasonably) pasted on a post, but big enough to reproduce your issue.
Let's say, as an example, that you are working with the iris data frame
head(iris)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 5.1 3.5 1.4 0.…
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
system
Closed
November 22, 2022, 11:03am
4
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.