按天(不是日期)和一天中的小时分组
group by day (not date) and hour of the day
如何按天(不是日期)和一天中的小时分组并计算读数?所以我会有7*24组。
library(lubridate)
library(dplyr)
readings <- ymd_hms(c("2018-01-05 12:00:15", "2018-01-01 02:00:15", "2018-02-25 12:00:15",
"2018-04-15 11:00:15", "2020-10-15 10:00:15", "2019-10-20 08:00:15",
"2019-11-15 02:01:15", "2018-11-02 11:00:15", "2018-07-09 02:00:15",
"2020-10-02 01:00:15", "2020-01-29 02:00:15", "2019-03-15 07:00:15")
)
tbl <- tibble(readings)
可以通过这种方式获得;
tbl %>%
mutate(day=wday(readings),hour=hour(readings)) %>%
group_by(day,hour)
如何按天(不是日期)和一天中的小时分组并计算读数?所以我会有7*24组。
library(lubridate)
library(dplyr)
readings <- ymd_hms(c("2018-01-05 12:00:15", "2018-01-01 02:00:15", "2018-02-25 12:00:15",
"2018-04-15 11:00:15", "2020-10-15 10:00:15", "2019-10-20 08:00:15",
"2019-11-15 02:01:15", "2018-11-02 11:00:15", "2018-07-09 02:00:15",
"2020-10-02 01:00:15", "2020-01-29 02:00:15", "2019-03-15 07:00:15")
)
tbl <- tibble(readings)
可以通过这种方式获得;
tbl %>%
mutate(day=wday(readings),hour=hour(readings)) %>%
group_by(day,hour)