Hi,
I have a dataset (df1
) with 5-minute intervals and I want to convert it into 4-minute data.
data looks like
date CO
<dttm> <dbl>
1 2019-05-01 00:00:00 246
2 2019-05-01 00:05:00 234
3 2019-05-01 00:10:00 235
4 2019-05-01 00:15:00 247
5 2019-05-01 00:20:00 256
6 2019-05-01 00:25:00 269
7 2019-05-01 00:30:00 249
8 2019-05-01 00:35:00 242
9 2019-05-01 00:40:00 229
10 2019-05-01 00:45:00 234
11 2019-05-01 00:50:00 226
12 2019-05-01 00:55:00 222
13 2019-05-01 01:00:00 238
14 2019-05-01 01:05:00 232
15 2019-05-01 01:10:00 280
For converting/averging into 4-minutes, I am using the code
df1 %>%
arrange(date) %>%
distinct(date, .keep_all= TRUE) %>% # remove duplicate rows based on header
mutate(hour = floor_date(date,'4 minute')) %>%
group_by(hour) %>%
summarise(across(where(is.numeric), ~ mean(.x, na.rm = TRUE)))
But, after applying this code, I am missing some dates on e.g. 00:36:00
in the data
# A tibble: 26,496 × 2
hour CO
<dttm> <dbl>
1 2019-05-01 00:00:00 246
2 2019-05-01 00:04:00 234
3 2019-05-01 00:08:00 235
4 2019-05-01 00:12:00 247
5 2019-05-01 00:20:00 256
6 2019-05-01 00:24:00 269
7 2019-05-01 00:28:00 249
8 2019-05-01 00:32:00 242
9 2019-05-01 00:40:00 229
10 2019-05-01 00:44:00 234
Please let me know how to merge missing dates
data can be found here Dropbox - NCore_CO_5min.csv - Simplify your life
Thanks