R Forecast 'ts' 对象必须有一个或多个观察

问题描述

不明白为什么会出现以下错误。我不习惯在 r 中使用 ts 对象。我可以看到数据中有观察。

head(bike_sales)
library(tidyverse)
library(lubridate)
library(zoo)
library(sweep)
library(tidyr)
library(forecast)
library(forecastHybrid)
library(timetk)
data <- bike_sales %>%
  mutate(order.month = as_date(as.yearmon(order.date))) %>%
  group_by(category.secondary,customer.id,order.month) %>%
  summarise(total.qty = sum(quantity))

nested_monthly <- data %>%
  group_by(category.secondary,customer.id) %>%
  rename()
  nest(.key = "series") %>%
  ungroup()

nested_monthly %>%
  mutate(train.ts = map(series,~.x %>% 
                          filter(order.month < make_date(2014,1,1)) %>%
                          tk_ts(frequency = 12,start = c(2011,1),end = c(2013,12),silent = T)),test.ts = map(series,~.x %>% 
                         filter(order.month >= make_date(2014,1)) %>%
                         tk_ts(frequency = 12,start = c(2014,end = c(2015,# aggregate results for yearly predictions
         train.ts.agg = map(train.ts,~.x %>% 
                              stats::filter(.,rep(1,sides = 1) %>%
                              stats::window(start = c(2011,12))),test.ts.agg = map(test.ts,~.x %>% 
                             stats::filter(.,sides = 1) %>%
                             stats::window(start = c(2014,12))))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)