library(dplyr)
library(fpp2) # for prison dataset
library(hts) # forecasting function
# prepare group time series
prison.gts <- gts(prison/1e3, characters = c(3,1,9),
gnames = c("State", "Gender", "Legal",
"State*Gender", "State*Legal",
"Gender*Legal"))
result_prison <- tidyr::crossing(methods = c('bu', 'comb'),
fmethod = c('arima')) %>%
mutate(forecast_result = purrr::map2(methods, fmethod,
~forecast.gts(prison.gts,method = .x, fmethod = .y)))
result_prison
# A tibble: 2 x 3
methods fmethod forecast_result
<chr> <chr> <list>
1 bu arima <gts>
2 comb arima <gts>
result_prison содержит столбец с именемcast_result, который определен как список.
В частности, мне интересно извлечь следующие данные из спискаcast_result в один большой тиббл без какого-либо объекта 'list' .
result_prison$forecast_result[[1]]$bts
result_prison$forecast_result[[1]]$histy
result_prison$forecast_result[[1]]$method # this is actually the same value from column methods
result_prison$forecast_result[[1]]$fmethod # this is actually the same value from column fmethods
В идеале, я думаю, что лучшая версия тиббла - это когда объекты списка раскрываются так, что у меня есть один большой тиббл с обычными типами, такими как char, double, et c. Нет списка объектов.
Я пытался
result_prison %>%
hoist(forecast_result,
hoisted_method = "method",
hoisted_fmethod = "fmethod",
bts = "bts",
histy = 'histy'
)
Хотя я все еще получал список объектов временных рядов в таблице.