Error: must be a vector, not a function.


I am trying to use the nested modeltime package to forecast multiple series in a dataframe. Before running the forecasts I am trying to convert the data into a time series using the following code:

to_ts <- function(data, freq = 4L) {
  dates <- data$quarter
  value <- data
  tk_ts(value, start = c(year(dates)[1], quarter(dates)[1]), frequency = freq) %>% 
    tk_tbl(timetk_idx = TRUE) %>% 
    rename(date = index)

nested_pfu_prob <- pfu_prob %>% 
select(-c(group_id,group_id2,sector,sector_cpart)) %>%
  group_by(instr_class,instr_code, cat,sector_label,sector_cpart_label,type) %>%

nested_pfu_prob_ts <- nested_pfu_prob %>%
  mutate(data.ts = map(.x = data.tbl, 
                       .f = to_ts))

unest_pfu_ts <- nested_pfu_prob_ts %>% 

The code works without any problems however, when moving on to the modeltime functions I get the following error:

# Modeltime

pfu_prob_nest <- pfu_prob_nested %>% 
    .id_var =  id,
    .date_var = quarter,
    .length_future = 12

..1` must be a vector, not a function.

Does anyone know how I can solve this error?

Thank you

I'm not familiar with the packages here, but a simple explanation is that you don't have a column id or quarter in pfu_prob_nested, so instead the name matches the function id() or the function quarter(), hence the error message.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.