这是一种选择。我们按“日期”和cut
在“临时”列上,然后summarise
得到频率n()
library(dplyr)
library(lubridate)
df %>%
group_by(Date = as.Date(dmy_hms(timestamp)), section,
Var1 = cut(temp, breaks=c(0,30,60,80,100,1000),
labels=c("0-30","30-60","60-80", "80-100", "100>"))) %>%
summarise(Freq = n())
# A tibble: 20 x 4
# Groups: Date, section [20]
# Date section Var1 Freq
# <date> <chr> <fct> <int>
# 1 2020-05-01 A 30-60 1
# 2 2020-05-01 B 0-30 1
# 3 2020-05-02 A 0-30 1
# 4 2020-05-02 B 30-60 1
# 5 2020-05-03 A 80-100 1
# 6 2020-05-03 B 30-60 1
# 7 2020-05-04 A 0-30 1
# 8 2020-05-04 B 0-30 1
# 9 2020-05-05 A 60-80 1
#10 2020-05-05 B 80-100 1
#11 2020-05-06 A 80-100 1
#12 2020-05-06 B 30-60 1
#13 2020-05-07 A 80-100 1
#14 2020-05-07 B 80-100 1
#15 2020-05-08 A 100> 1
#16 2020-05-08 B 60-80 1
#17 2020-05-09 A 100> 1
#18 2020-05-09 B 0-30 1
#19 2020-05-10 A 0-30 1
#20 2020-05-10 B 0-30 1
data
df <- structure(list(timestamp = c("01-05-2020 00:01:22", "02-05-2020 00:01:22",
"03-05-2020 00:01:22", "04-05-2020 00:01:22", "05-05-2020 00:01:22",
"06-05-2020 00:01:22", "07-05-2020 00:01:22", "08-05-2020 00:01:22",
"09-05-2020 00:01:22", "10-05-2020 00:01:22", "01-05-2020 00:01:22",
"02-05-2020 00:01:22", "03-05-2020 00:01:22", "04-05-2020 00:01:22",
"05-05-2020 00:01:22", "06-05-2020 00:01:22", "07-05-2020 00:01:22",
"08-05-2020 00:01:22", "09-05-2020 00:01:22", "10-05-2020 00:01:22"
), section = c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B"), temp = c(45L,
10L, 98L, 23L, 67L, 89L, 100L, 110L, 123L, 12L, 23L, 44L, 55L,
12L, 98L, 45L, 87L, 65L, 12L, 8L)), class = "data.frame", row.names = c(NA,
-20L))