I would like to cut the date range according to the defined breaks (0-7 days, 8-15 days, ..., 31-50 days), then calculate the group average of the values.
library(dplyr)
date = seq(as.Date("2019/1/1"), by = "day", length.out = 50)
value = matrix(rnorm(200, 100, 50), nrow=50) %>% data.frame()
sample = cbind(date, value) %>% data.frame()
breaks = c(0, 7, 15, 30, 50)
sample %>%
group_by(cutt = cut(StayDate, breaks=breaks)) %>%
summarise(m1 = mean(X1), m2=mean(X2))
However, it seems that cut function can only use "day", "week", etc. to cut. Is there any way I can make it?