Часть 1 - Показать частоту наблюдений на основе дня недели
library(dplyr)
library(lubridate)
df %>%
mutate(date = as.Date(date),
wday = weekdays(date)) %>%
count(wday)
# wday n
# <chr> <int>
#1 Friday 1
#2 Saturday 2
#3 Sunday 3
#4 Thursday 3
#5 Tuesday 3
Часть 2 - Показать частоту наблюдений на основе времени
df %>%
mutate(pers = period_to_seconds(hms(format(as.POSIXct(time,
format = "%I:%M %p"), "%T"))),
group = cut(pers, seq(0, 86400, 1800), labels = FALSE)) %>%
count(group)
# group n
# <int> <int>
# 1 1 1
# 2 7 1
# 3 9 1
# 4 16 1
# 5 27 1
# 6 34 1
# 7 35 2
# 8 37 1
# 9 42 1
#10 43 2
Где group
будет иметь номер1-48 для каждых 30 минут дня.
данные
df <- structure(list(date = structure(c(1L, 1L, 2L, 3L, 3L, 4L, 5L,
5L, 6L, 7L, 7L, 8L), .Label = c("2019-09-01", "2019-09-03", "2019-09-05",
"2019-09-06", "2019-10-01", "2019-10-03", "2019-10-05", "2019-10-06"
), class = "factor"), time = structure(c(4L, 7L, 3L, 12L, 2L,
10L, 5L, 9L, 1L, 8L, 11L, 6L), .Label = c("01:11 PM", "03:02 AM",
"04:13 AM", "05:00 PM", "05:01 PM", "05:22 PM", "06:10 PM", "07:43 AM",
"08:34 PM", "09:22 PM", "09:29 PM", "12:19 AM"), class = "factor")),
class = "data.frame", row.names = c(NA, -12L))