在 Dplyr 中排除 Dot 中的周末

Exclude Weekends in Dot in Dplyr

这是此答案的延续问题:

我正在 prophet 包中的 dplyr 中使用 do 函数。尝试这样做时,我想制作一个排除周末的未来数据框。以下是我当前的代码:

当前数据帧:

dataset
          ds     group     y
  2021-12-15         A     5
  2021-12-16         A     6
  2021-12-15         B    10
  2021-12-16         B     7
         etc       etc   etc

预测

library(dplyr)
library(prophet)

data = dataset %>%  
group_by(group) %>%
do(predict(prophet(., daily.seasonality = TRUE, yearly.seasonality = TRUE), 
make_future_dataframe(prophet(.,daily.seasonality = TRUE, yearly.seasonality = TRUE), periods = 14))) %>%
select(ds, group, yhat)

如何重写上面的代码来过滤 make_future_dataframe 没有周末的数据集?

我希望它看起来像这样,但这不起作用:

data = dataset %>%  
  group_by(group) %>%
  do(predict(prophet(., daily.seasonality = TRUE, yearly.seasonality = TRUE), 
  make_future_dataframe(prophet(.[which(weekdays(.$ds) != 'Saturday' | weekdays(.$ds) != 'Sunday'),],daily.seasonality = TRUE, yearly.seasonality = TRUE), periods = 14))) %>%
  select(ds, group, yhat)

我们可以在预测之前删除周末:

df %>% 
  group_by(group) %>% 
  mutate(weekdays = weekdays(ds)) %>% 
  filter(weekdays != "Saturday" & weekdays != "Sunday") %>% 
  do(predict(prophet(., daily.seasonality = TRUE, yearly.seasonality = TRUE), 
  filter(make_future_dataframe(prophet(., daily.seasonality = TRUE, yearly.seasonality = TRUE), periods = 14), weekdays(ds) != "Saturday" & weekdays(ds) != "Sunday"))) %>%
  select(ds, group, yhat)