Мы. может конвертировать. в длинное форматирование с помощью pivot_longer
после unnest
, используя 'list_of_weights' и затем получить весовые коэффициенты из столбца 'list_of_weights' с parse_number
library(dplyr)
library(tidyr)
library(stringr)
df1 %>%
unnest(c(list_of_weights)) %>%
pivot_longer(cols = ets:theta, names_to = 'model_type',
values_to = 'model_fcst') %>%
filter(str_detect(list_of_weights, model_type)) %>%
mutate(weights = readr::parse_number(list_of_weights)) %>%
select(-list_of_weights)
# A tibble: 6 x 3
# model_type model_fcst weights
# <chr> <chr> <dbl>
#1 ets forecast 0.5
#2 arima forecast 0.2
#3 theta forecast 0.3
#4 ets forecast 0.4
#5 arima forecast 0.1
#6 theta forecast 0.5
data
df1 <- structure(list(ets = c("forecast", "forecast"), arima = c("forecast",
"forecast"), theta = c("forecast", "forecast"), list_of_weights = list(
c("ets_weight:0.5", "arima_weight:0.2", "theta_weight:0.3"
), c("ets_weight:0.4", "arima_weight:0.1", "theta_weight:0.5"
))), row.names = c(NA, -2L), class = "data.frame")